blob: c2e6e186e459c67338fc783b5c760bf24b5a1671 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/jsepsessiondescription.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/mediastreaminterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/peerconnectioninterface.h"
19#include "webrtc/api/rtpreceiverinterface.h"
20#include "webrtc/api/rtpsenderinterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010021#include "webrtc/api/test/fakeconstraints.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000022#include "webrtc/base/gunit.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000023#include "webrtc/base/ssladapter.h"
24#include "webrtc/base/sslstreamadapter.h"
25#include "webrtc/base/stringutils.h"
26#include "webrtc/base/thread.h"
kjellandera96e2d72016-02-04 23:52:28 -080027#include "webrtc/media/base/fakevideocapturer.h"
deadbeef953c2ce2017-01-09 14:53:41 -080028#include "webrtc/media/sctp/sctptransportinternal.h"
kwiberg1e4e8cb2017-01-31 01:48:08 -080029#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.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:
kjellander71a1b612016-11-07 01:18:08 -0800529 // We need these using declarations because there are two versions of each of
530 // the below methods and we only override one of them.
531 // TODO(deadbeef): Remove once there's only one version of the methods.
532 using PeerConnectionObserver::OnAddStream;
533 using PeerConnectionObserver::OnRemoveStream;
534 using PeerConnectionObserver::OnDataChannel;
535
deadbeefab9b2d12015-10-14 11:33:11 -0700536 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200537 virtual ~MockPeerConnectionObserver() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 }
539 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
540 pc_ = pc;
541 if (pc) {
542 state_ = pc_->signaling_state();
543 }
544 }
nisseef8b61e2016-04-29 06:09:15 -0700545 void OnSignalingChange(
546 PeerConnectionInterface::SignalingState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547 EXPECT_EQ(pc_->signaling_state(), new_state);
548 state_ = new_state;
549 }
deadbeefab9b2d12015-10-14 11:33:11 -0700550
551 MediaStreamInterface* RemoteStream(const std::string& label) {
552 return remote_streams_->find(label);
553 }
554 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700555 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 last_added_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700557 remote_streams_->AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700559 void OnRemoveStream(
560 rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 last_removed_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700562 remote_streams_->RemoveStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 }
perkjdfb769d2016-02-09 03:09:43 -0800564 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700565 void OnDataChannel(
566 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 last_datachannel_ = data_channel;
568 }
569
perkjdfb769d2016-02-09 03:09:43 -0800570 void OnIceConnectionChange(
571 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 EXPECT_EQ(pc_->ice_connection_state(), new_state);
zhihuang81c3a032016-11-17 12:06:24 -0800573 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 }
perkjdfb769d2016-02-09 03:09:43 -0800575 void OnIceGatheringChange(
576 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
perkjdfb769d2016-02-09 03:09:43 -0800578 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete;
zhihuang81c3a032016-11-17 12:06:24 -0800579 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 }
perkjdfb769d2016-02-09 03:09:43 -0800581 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
583 pc_->ice_gathering_state());
584
585 std::string sdp;
586 EXPECT_TRUE(candidate->ToString(&sdp));
587 EXPECT_LT(0u, sdp.size());
588 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
589 candidate->sdp_mline_index(), sdp, NULL));
590 EXPECT_TRUE(last_candidate_.get() != NULL);
zhihuang81c3a032016-11-17 12:06:24 -0800591 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700592 }
593
594 void OnIceCandidatesRemoved(
595 const std::vector<cricket::Candidate>& candidates) override {
zhihuang81c3a032016-11-17 12:06:24 -0800596 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700597 }
598
599 void OnIceConnectionReceivingChange(bool receiving) override {
zhihuang81c3a032016-11-17 12:06:24 -0800600 callback_triggered_ = true;
601 }
602
zhihuangc63b8942016-12-02 15:41:10 -0800603 void OnAddTrack(
604 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
605 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
606 streams) override {
zhihuang81c3a032016-11-17 12:06:24 -0800607 EXPECT_TRUE(receiver != nullptr);
608 num_added_tracks_++;
609 last_added_track_label_ = receiver->id();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611
612 // Returns the label of the last added stream.
613 // Empty string if no stream have been added.
614 std::string GetLastAddedStreamLabel() {
615 if (last_added_stream_.get())
616 return last_added_stream_->label();
617 return "";
618 }
619 std::string GetLastRemovedStreamLabel() {
620 if (last_removed_stream_.get())
621 return last_removed_stream_->label();
622 return "";
623 }
624
zhihuang9763d562016-08-05 11:14:50 -0700625 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 PeerConnectionInterface::SignalingState state_;
kwibergd1fe2812016-04-27 06:47:29 -0700627 std::unique_ptr<IceCandidateInterface> last_candidate_;
zhihuang9763d562016-08-05 11:14:50 -0700628 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
deadbeefab9b2d12015-10-14 11:33:11 -0700629 rtc::scoped_refptr<StreamCollection> remote_streams_;
630 bool renegotiation_needed_ = false;
631 bool ice_complete_ = false;
zhihuang81c3a032016-11-17 12:06:24 -0800632 bool callback_triggered_ = false;
633 int num_added_tracks_ = 0;
634 std::string last_added_track_label_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635
636 private:
zhihuang9763d562016-08-05 11:14:50 -0700637 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
638 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639};
640
641} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700642
zhihuang29ff8442016-07-27 11:07:25 -0700643// The PeerConnectionMediaConfig tests below verify that configuration
644// and constraints are propagated into the MediaConfig passed to
645// CreateMediaController. These settings are intended for MediaChannel
646// constructors, but that is not exercised by these unittest.
647class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
648 public:
kwiberg1e4e8cb2017-01-31 01:48:08 -0800649 PeerConnectionFactoryForTest()
650 : webrtc::PeerConnectionFactory(
651 webrtc::CreateBuiltinAudioEncoderFactory(),
652 webrtc::CreateBuiltinAudioDecoderFactory()) {}
653
zhihuang29ff8442016-07-27 11:07:25 -0700654 webrtc::MediaControllerInterface* CreateMediaController(
skvlad11a9cbf2016-10-07 11:53:05 -0700655 const cricket::MediaConfig& config,
656 webrtc::RtcEventLog* event_log) const override {
zhihuang29ff8442016-07-27 11:07:25 -0700657 create_media_controller_called_ = true;
658 create_media_controller_config_ = config;
659
660 webrtc::MediaControllerInterface* mc =
skvlad11a9cbf2016-10-07 11:53:05 -0700661 PeerConnectionFactory::CreateMediaController(config, event_log);
zhihuang29ff8442016-07-27 11:07:25 -0700662 EXPECT_TRUE(mc != nullptr);
663 return mc;
664 }
665
666 cricket::TransportController* CreateTransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700667 cricket::PortAllocator* port_allocator,
668 bool redetermine_role_on_ice_restart) override {
zhihuang29ff8442016-07-27 11:07:25 -0700669 transport_controller = new cricket::TransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700670 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
671 redetermine_role_on_ice_restart);
zhihuang29ff8442016-07-27 11:07:25 -0700672 return transport_controller;
673 }
674
675 cricket::TransportController* transport_controller;
676 // Mutable, so they can be modified in the above const-declared method.
677 mutable bool create_media_controller_called_ = false;
678 mutable cricket::MediaConfig create_media_controller_config_;
679};
680
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681class PeerConnectionInterfaceTest : public testing::Test {
682 protected:
phoglund37ebcf02016-01-08 05:04:57 -0800683 PeerConnectionInterfaceTest() {
684#ifdef WEBRTC_ANDROID
685 webrtc::InitializeAndroidObjects();
686#endif
687 }
688
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 virtual void SetUp() {
690 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700691 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
692 nullptr, nullptr, nullptr);
693 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700694 pc_factory_for_test_ =
695 new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
696 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 }
698
699 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700700 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 }
702
deadbeef293e9262017-01-11 12:28:30 -0800703 // DTLS does not work in a loopback call, so is disabled for most of the
704 // tests in this file.
705 void CreatePeerConnectionWithoutDtls() {
706 FakeConstraints no_dtls_constraints;
707 no_dtls_constraints.AddMandatory(
708 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
709
710 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
711 &no_dtls_constraints);
712 }
713
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700715 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
716 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 }
718
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 void CreatePeerConnectionWithIceTransportsType(
720 PeerConnectionInterface::IceTransportsType type) {
721 PeerConnectionInterface::RTCConfiguration config;
722 config.type = type;
723 return CreatePeerConnection(config, nullptr);
724 }
725
726 void CreatePeerConnectionWithIceServer(const std::string& uri,
727 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800728 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 server.uri = uri;
731 server.password = password;
732 config.servers.push_back(server);
733 CreatePeerConnection(config, nullptr);
734 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700736 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
737 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700738 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800739 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
740 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000741
Henrik Boströmd79599d2016-06-01 13:58:50 +0200742 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000743 bool dtls;
744 if (FindConstraint(constraints,
745 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
746 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200747 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800748 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
749 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000750 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200751 pc_ = pc_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800752 config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200753 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 ASSERT_TRUE(pc_.get() != NULL);
755 observer_.SetPeerConnectionInterface(pc_.get());
756 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
757 }
758
deadbeef0a6c4ca2015-10-06 11:38:28 -0700759 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800760 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700761 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700762 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800763 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700764
zhihuang9763d562016-08-05 11:14:50 -0700765 rtc::scoped_refptr<PeerConnectionInterface> pc;
hbosd7973cc2016-05-27 06:08:53 -0700766 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
767 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800768 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700769 }
770
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700772 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800773 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
774 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
775 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800777 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778
deadbeef0a6c4ca2015-10-06 11:38:28 -0700779 CreatePeerConnectionExpectFail(kStunInvalidPort);
780 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
781 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700783 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800784 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
785 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800787 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800789 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800791 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 }
793
794 void ReleasePeerConnection() {
795 pc_ = NULL;
796 observer_.SetPeerConnectionInterface(NULL);
797 }
798
deadbeefab9b2d12015-10-14 11:33:11 -0700799 void AddVideoStream(const std::string& label) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700801 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700803 rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
zhihuang9763d562016-08-05 11:14:50 -0700805 rtc::scoped_refptr<VideoTrackInterface> video_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 pc_factory_->CreateVideoTrack(label + "v0", video_source));
807 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000808 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
810 observer_.renegotiation_needed_ = false;
811 }
812
813 void AddVoiceStream(const std::string& label) {
814 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700815 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700817 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 pc_factory_->CreateAudioTrack(label + "a0", NULL));
819 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000820 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
822 observer_.renegotiation_needed_ = false;
823 }
824
825 void AddAudioVideoStream(const std::string& stream_label,
826 const std::string& audio_track_label,
827 const std::string& video_track_label) {
828 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700829 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 pc_factory_->CreateLocalMediaStream(stream_label));
zhihuang9763d562016-08-05 11:14:50 -0700831 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 pc_factory_->CreateAudioTrack(
833 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
834 stream->AddTrack(audio_track.get());
zhihuang9763d562016-08-05 11:14:50 -0700835 rtc::scoped_refptr<VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -0700836 pc_factory_->CreateVideoTrack(
837 video_track_label,
838 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000840 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
842 observer_.renegotiation_needed_ = false;
843 }
844
kwibergd1fe2812016-04-27 06:47:29 -0700845 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700846 bool offer,
847 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000848 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
849 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 MockCreateSessionDescriptionObserver>());
851 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700852 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700854 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 }
856 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
kwiberg2bbff992016-03-16 11:03:04 -0700857 desc->reset(observer->release_desc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 return observer->result();
859 }
860
kwibergd1fe2812016-04-27 06:47:29 -0700861 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700862 MediaConstraintsInterface* constraints) {
863 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 }
865
kwibergd1fe2812016-04-27 06:47:29 -0700866 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700867 MediaConstraintsInterface* constraints) {
868 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 }
870
871 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000872 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
873 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 MockSetSessionDescriptionObserver>());
875 if (local) {
876 pc_->SetLocalDescription(observer, desc);
877 } else {
878 pc_->SetRemoteDescription(observer, desc);
879 }
zhihuang29ff8442016-07-27 11:07:25 -0700880 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
881 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 return observer->result();
884 }
885
886 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
887 return DoSetSessionDescription(desc, true);
888 }
889
890 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
891 return DoSetSessionDescription(desc, false);
892 }
893
894 // Calls PeerConnection::GetStats and check the return value.
895 // It does not verify the values in the StatReports since a RTCP packet might
896 // be required.
897 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000898 rtc::scoped_refptr<MockStatsObserver> observer(
899 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000900 if (!pc_->GetStats(
901 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 return false;
903 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
904 return observer->called();
905 }
906
907 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800908 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 // Create a local stream with audio&video tracks.
910 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
911 CreateOfferReceiveAnswer();
912 }
913
914 // Verify that RTP Header extensions has been negotiated for audio and video.
915 void VerifyRemoteRtpHeaderExtensions() {
916 const cricket::MediaContentDescription* desc =
917 cricket::GetFirstAudioContentDescription(
918 pc_->remote_description()->description());
919 ASSERT_TRUE(desc != NULL);
920 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
921
922 desc = cricket::GetFirstVideoContentDescription(
923 pc_->remote_description()->description());
924 ASSERT_TRUE(desc != NULL);
925 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
926 }
927
928 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700929 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700930 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 std::string sdp;
932 EXPECT_TRUE(offer->ToString(&sdp));
933 SessionDescriptionInterface* remote_offer =
934 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
935 sdp, NULL);
936 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
937 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
938 }
939
deadbeefab9b2d12015-10-14 11:33:11 -0700940 void CreateAndSetRemoteOffer(const std::string& sdp) {
941 SessionDescriptionInterface* remote_offer =
942 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
943 sdp, nullptr);
944 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
945 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
946 }
947
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700949 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700950 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951
952 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
953 // audio codec change, even if the parameter has nothing to do with
954 // receiving. Not all parameters are serialized to SDP.
955 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
956 // the SessionDescription, it is necessary to do that here to in order to
957 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
958 // https://code.google.com/p/webrtc/issues/detail?id=1356
959 std::string sdp;
960 EXPECT_TRUE(answer->ToString(&sdp));
961 SessionDescriptionInterface* new_answer =
962 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
963 sdp, NULL);
964 EXPECT_TRUE(DoSetLocalDescription(new_answer));
965 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
966 }
967
968 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700969 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700970 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971
972 std::string sdp;
973 EXPECT_TRUE(answer->ToString(&sdp));
974 SessionDescriptionInterface* pr_answer =
975 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
976 sdp, NULL);
977 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
978 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
979 }
980
981 void CreateOfferReceiveAnswer() {
982 CreateOfferAsLocalDescription();
983 std::string sdp;
984 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
985 CreateAnswerAsRemoteDescription(sdp);
986 }
987
988 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700989 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700990 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
992 // audio codec change, even if the parameter has nothing to do with
993 // receiving. Not all parameters are serialized to SDP.
994 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
995 // the SessionDescription, it is necessary to do that here to in order to
996 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
997 // https://code.google.com/p/webrtc/issues/detail?id=1356
998 std::string sdp;
999 EXPECT_TRUE(offer->ToString(&sdp));
1000 SessionDescriptionInterface* new_offer =
1001 webrtc::CreateSessionDescription(
1002 SessionDescriptionInterface::kOffer,
1003 sdp, NULL);
1004
1005 EXPECT_TRUE(DoSetLocalDescription(new_offer));
1006 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001007 // Wait for the ice_complete message, so that SDP will have candidates.
1008 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 }
1010
deadbeefab9b2d12015-10-14 11:33:11 -07001011 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1013 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001014 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 EXPECT_TRUE(DoSetRemoteDescription(answer));
1016 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1017 }
1018
deadbeefab9b2d12015-10-14 11:33:11 -07001019 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 webrtc::JsepSessionDescription* pr_answer =
1021 new webrtc::JsepSessionDescription(
1022 SessionDescriptionInterface::kPrAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001023 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
1025 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
1026 webrtc::JsepSessionDescription* answer =
1027 new webrtc::JsepSessionDescription(
1028 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001029 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 EXPECT_TRUE(DoSetRemoteDescription(answer));
1031 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1032 }
1033
1034 // Help function used for waiting until a the last signaled remote stream has
1035 // the same label as |stream_label|. In a few of the tests in this file we
1036 // answer with the same session description as we offer and thus we can
1037 // check if OnAddStream have been called with the same stream as we offer to
1038 // send.
1039 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
1040 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
1041 }
1042
1043 // Creates an offer and applies it as a local session description.
1044 // Creates an answer with the same SDP an the offer but removes all lines
1045 // that start with a:ssrc"
1046 void CreateOfferReceiveAnswerWithoutSsrc() {
1047 CreateOfferAsLocalDescription();
1048 std::string sdp;
1049 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1050 SetSsrcToZero(&sdp);
1051 CreateAnswerAsRemoteDescription(sdp);
1052 }
1053
deadbeefab9b2d12015-10-14 11:33:11 -07001054 // This function creates a MediaStream with label kStreams[0] and
1055 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1056 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001057 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001058 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001059 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001060 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1061 size_t number_of_video_tracks) {
1062 EXPECT_LE(number_of_audio_tracks, 2u);
1063 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001064
1065 reference_collection_ = StreamCollection::Create();
1066 std::string sdp_ms1 = std::string(kSdpStringInit);
1067
1068 std::string mediastream_label = kStreams[0];
1069
1070 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1071 webrtc::MediaStream::Create(mediastream_label));
1072 reference_collection_->AddStream(stream);
1073
1074 if (number_of_audio_tracks > 0) {
1075 sdp_ms1 += std::string(kSdpStringAudio);
1076 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1077 AddAudioTrack(kAudioTracks[0], stream);
1078 }
1079 if (number_of_audio_tracks > 1) {
1080 sdp_ms1 += kSdpStringMs1Audio1;
1081 AddAudioTrack(kAudioTracks[1], stream);
1082 }
1083
1084 if (number_of_video_tracks > 0) {
1085 sdp_ms1 += std::string(kSdpStringVideo);
1086 sdp_ms1 += std::string(kSdpStringMs1Video0);
1087 AddVideoTrack(kVideoTracks[0], stream);
1088 }
1089 if (number_of_video_tracks > 1) {
1090 sdp_ms1 += kSdpStringMs1Video1;
1091 AddVideoTrack(kVideoTracks[1], stream);
1092 }
1093
kwibergd1fe2812016-04-27 06:47:29 -07001094 return std::unique_ptr<SessionDescriptionInterface>(
kwiberg2bbff992016-03-16 11:03:04 -07001095 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1096 sdp_ms1, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001097 }
1098
1099 void AddAudioTrack(const std::string& track_id,
1100 MediaStreamInterface* stream) {
1101 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1102 webrtc::AudioTrack::Create(track_id, nullptr));
1103 ASSERT_TRUE(stream->AddTrack(audio_track));
1104 }
1105
1106 void AddVideoTrack(const std::string& track_id,
1107 MediaStreamInterface* stream) {
1108 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001109 webrtc::VideoTrack::Create(track_id,
1110 webrtc::FakeVideoTrackSource::Create()));
deadbeefab9b2d12015-10-14 11:33:11 -07001111 ASSERT_TRUE(stream->AddTrack(video_track));
1112 }
1113
kwibergfd8be342016-05-14 19:44:11 -07001114 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
deadbeef293e9262017-01-11 12:28:30 -08001115 CreatePeerConnectionWithoutDtls();
zhihuang8f65cdf2016-05-06 18:40:30 -07001116 AddVoiceStream(kStreamLabel1);
kwibergfd8be342016-05-14 19:44:11 -07001117 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001118 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1119 return offer;
1120 }
1121
kwibergfd8be342016-05-14 19:44:11 -07001122 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001123 CreateAnswerWithOneAudioStream() {
kwibergfd8be342016-05-14 19:44:11 -07001124 std::unique_ptr<SessionDescriptionInterface> offer =
zhihuang8f65cdf2016-05-06 18:40:30 -07001125 CreateOfferWithOneAudioStream();
1126 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergfd8be342016-05-14 19:44:11 -07001127 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001128 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1129 return answer;
1130 }
1131
1132 const std::string& GetFirstAudioStreamCname(
1133 const SessionDescriptionInterface* desc) {
1134 const cricket::ContentInfo* audio_content =
1135 cricket::GetFirstAudioContent(desc->description());
1136 const cricket::AudioContentDescription* audio_desc =
1137 static_cast<const cricket::AudioContentDescription*>(
1138 audio_content->description);
1139 return audio_desc->streams()[0].cname;
1140 }
1141
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001142 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001143 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001144 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1145 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1146 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001148 rtc::scoped_refptr<StreamCollection> reference_collection_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149};
1150
zhihuang29ff8442016-07-27 11:07:25 -07001151// Test that no callbacks on the PeerConnectionObserver are called after the
1152// PeerConnection is closed.
1153TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) {
zhihuang9763d562016-08-05 11:14:50 -07001154 rtc::scoped_refptr<PeerConnectionInterface> pc(
zhihuang29ff8442016-07-27 11:07:25 -07001155 pc_factory_for_test_->CreatePeerConnection(
1156 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr,
1157 nullptr, &observer_));
1158 observer_.SetPeerConnectionInterface(pc.get());
1159 pc->Close();
1160
1161 // No callbacks is expected to be called.
zhihuang81c3a032016-11-17 12:06:24 -08001162 observer_.callback_triggered_ = false;
zhihuang29ff8442016-07-27 11:07:25 -07001163 std::vector<cricket::Candidate> candidates;
1164 pc_factory_for_test_->transport_controller->SignalGatheringState(
1165 cricket::IceGatheringState{});
1166 pc_factory_for_test_->transport_controller->SignalCandidatesGathered(
1167 "", candidates);
1168 pc_factory_for_test_->transport_controller->SignalConnectionState(
1169 cricket::IceConnectionState{});
1170 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved(
1171 candidates);
1172 pc_factory_for_test_->transport_controller->SignalReceiving(false);
zhihuang81c3a032016-11-17 12:06:24 -08001173 EXPECT_FALSE(observer_.callback_triggered_);
zhihuang29ff8442016-07-27 11:07:25 -07001174}
1175
zhihuang8f65cdf2016-05-06 18:40:30 -07001176// Generate different CNAMEs when PeerConnections are created.
1177// The CNAMEs are expected to be generated randomly. It is possible
1178// that the test fails, though the possibility is very low.
1179TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001180 std::unique_ptr<SessionDescriptionInterface> offer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001181 CreateOfferWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001182 std::unique_ptr<SessionDescriptionInterface> offer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001183 CreateOfferWithOneAudioStream();
1184 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1185 GetFirstAudioStreamCname(offer2.get()));
1186}
1187
1188TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001189 std::unique_ptr<SessionDescriptionInterface> answer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001190 CreateAnswerWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001191 std::unique_ptr<SessionDescriptionInterface> answer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001192 CreateAnswerWithOneAudioStream();
1193 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1194 GetFirstAudioStreamCname(answer2.get()));
1195}
1196
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197TEST_F(PeerConnectionInterfaceTest,
1198 CreatePeerConnectionWithDifferentConfigurations) {
1199 CreatePeerConnectionWithDifferentConfigurations();
1200}
1201
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001202TEST_F(PeerConnectionInterfaceTest,
1203 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1204 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1205 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1206 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1207 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1208 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1209 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1210 port_allocator_->candidate_filter());
1211 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1212 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1213}
1214
1215// Test that when a PeerConnection is created with a nonzero candidate pool
1216// size, the pooled PortAllocatorSession is created with all the attributes
1217// in the RTCConfiguration.
1218TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1219 PeerConnectionInterface::RTCConfiguration config;
1220 PeerConnectionInterface::IceServer server;
1221 server.uri = kStunAddressOnly;
1222 config.servers.push_back(server);
1223 config.type = PeerConnectionInterface::kRelay;
1224 config.disable_ipv6 = true;
1225 config.tcp_candidate_policy =
1226 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001227 config.candidate_network_policy =
1228 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001229 config.ice_candidate_pool_size = 1;
1230 CreatePeerConnection(config, nullptr);
1231
1232 const cricket::FakePortAllocatorSession* session =
1233 static_cast<const cricket::FakePortAllocatorSession*>(
1234 port_allocator_->GetPooledSession());
1235 ASSERT_NE(nullptr, session);
1236 EXPECT_EQ(1UL, session->stun_servers().size());
1237 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1238 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001239 EXPECT_LT(0U,
1240 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001241}
1242
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001243// Test that the PeerConnection initializes the port allocator passed into it,
1244// and on the correct thread.
1245TEST_F(PeerConnectionInterfaceTest,
1246 CreatePeerConnectionInitializesPortAllocator) {
1247 rtc::Thread network_thread;
1248 network_thread.Start();
1249 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1250 webrtc::CreatePeerConnectionFactory(
1251 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
1252 nullptr, nullptr, nullptr));
1253 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1254 new cricket::FakePortAllocator(&network_thread, nullptr));
1255 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1256 PeerConnectionInterface::RTCConfiguration config;
1257 rtc::scoped_refptr<PeerConnectionInterface> pc(
1258 pc_factory->CreatePeerConnection(
1259 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1260 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1261 // so all we have to do here is check that it's initialized.
1262 EXPECT_TRUE(raw_port_allocator->initialized());
1263}
1264
deadbeef46c73892016-11-16 19:42:04 -08001265// Check that GetConfiguration returns the configuration the PeerConnection was
1266// constructed with, before SetConfiguration is called.
1267TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1268 PeerConnectionInterface::RTCConfiguration config;
1269 config.type = PeerConnectionInterface::kRelay;
1270 CreatePeerConnection(config, nullptr);
1271
1272 PeerConnectionInterface::RTCConfiguration returned_config =
1273 pc_->GetConfiguration();
1274 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1275}
1276
1277// Check that GetConfiguration returns the last configuration passed into
1278// SetConfiguration.
1279TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1280 CreatePeerConnection();
1281
1282 PeerConnectionInterface::RTCConfiguration config;
1283 config.type = PeerConnectionInterface::kRelay;
1284 EXPECT_TRUE(pc_->SetConfiguration(config));
1285
1286 PeerConnectionInterface::RTCConfiguration returned_config =
1287 pc_->GetConfiguration();
1288 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1289}
1290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291TEST_F(PeerConnectionInterfaceTest, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001292 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001293 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 AddVoiceStream(kStreamLabel2);
1295 ASSERT_EQ(2u, pc_->local_streams()->count());
1296
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001297 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001298 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
zhihuang9763d562016-08-05 11:14:50 -07001300 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1301 pc_factory_->CreateAudioTrack(kStreamLabel3,
1302 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001304 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001305 EXPECT_EQ(3u, pc_->local_streams()->count());
1306
1307 // Remove the third stream.
1308 pc_->RemoveStream(pc_->local_streams()->at(2));
1309 EXPECT_EQ(2u, pc_->local_streams()->count());
1310
1311 // Remove the second stream.
1312 pc_->RemoveStream(pc_->local_streams()->at(1));
1313 EXPECT_EQ(1u, pc_->local_streams()->count());
1314
1315 // Remove the first stream.
1316 pc_->RemoveStream(pc_->local_streams()->at(0));
1317 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318}
1319
deadbeefab9b2d12015-10-14 11:33:11 -07001320// Test that the created offer includes streams we added.
1321TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001322 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001323 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001324 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001325 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001326
1327 const cricket::ContentInfo* audio_content =
1328 cricket::GetFirstAudioContent(offer->description());
1329 const cricket::AudioContentDescription* audio_desc =
1330 static_cast<const cricket::AudioContentDescription*>(
1331 audio_content->description);
1332 EXPECT_TRUE(
1333 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1334
1335 const cricket::ContentInfo* video_content =
1336 cricket::GetFirstVideoContent(offer->description());
1337 const cricket::VideoContentDescription* video_desc =
1338 static_cast<const cricket::VideoContentDescription*>(
1339 video_content->description);
1340 EXPECT_TRUE(
1341 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1342
1343 // Add another stream and ensure the offer includes both the old and new
1344 // streams.
1345 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001346 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001347
1348 audio_content = cricket::GetFirstAudioContent(offer->description());
1349 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1350 audio_content->description);
1351 EXPECT_TRUE(
1352 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1353 EXPECT_TRUE(
1354 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1355
1356 video_content = cricket::GetFirstVideoContent(offer->description());
1357 video_desc = static_cast<const cricket::VideoContentDescription*>(
1358 video_content->description);
1359 EXPECT_TRUE(
1360 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1361 EXPECT_TRUE(
1362 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1363}
1364
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001366 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001367 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 ASSERT_EQ(1u, pc_->local_streams()->count());
1369 pc_->RemoveStream(pc_->local_streams()->at(0));
1370 EXPECT_EQ(0u, pc_->local_streams()->count());
1371}
1372
deadbeefe1f9d832016-01-14 15:35:42 -08001373// Test for AddTrack and RemoveTrack methods.
1374// Tests that the created offer includes tracks we added,
1375// and that the RtpSenders are created correctly.
1376// Also tests that RemoveTrack removes the tracks from subsequent offers.
1377TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001378 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001379 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001380 rtc::scoped_refptr<MediaStreamInterface> stream(
deadbeefe1f9d832016-01-14 15:35:42 -08001381 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1382 std::vector<MediaStreamInterface*> stream_list;
1383 stream_list.push_back(stream.get());
zhihuang9763d562016-08-05 11:14:50 -07001384 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001385 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001386 rtc::scoped_refptr<VideoTrackInterface> video_track(
1387 pc_factory_->CreateVideoTrack(
1388 "video_track",
1389 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefe1f9d832016-01-14 15:35:42 -08001390 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1391 auto video_sender = pc_->AddTrack(video_track, stream_list);
deadbeefa601f5c2016-06-06 14:27:39 -07001392 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1393 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001394 EXPECT_EQ("audio_track", audio_sender->id());
1395 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001396 EXPECT_EQ(1UL, video_sender->stream_ids().size());
1397 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001398 EXPECT_EQ("video_track", video_sender->id());
1399 EXPECT_EQ(video_track, video_sender->track());
1400
1401 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001402 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001403 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001404
1405 const cricket::ContentInfo* audio_content =
1406 cricket::GetFirstAudioContent(offer->description());
1407 const cricket::AudioContentDescription* audio_desc =
1408 static_cast<const cricket::AudioContentDescription*>(
1409 audio_content->description);
1410 EXPECT_TRUE(
1411 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1412
1413 const cricket::ContentInfo* video_content =
1414 cricket::GetFirstVideoContent(offer->description());
1415 const cricket::VideoContentDescription* video_desc =
1416 static_cast<const cricket::VideoContentDescription*>(
1417 video_content->description);
1418 EXPECT_TRUE(
1419 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1420
1421 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1422
1423 // Now try removing the tracks.
1424 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1425 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1426
1427 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001428 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001429
1430 audio_content = cricket::GetFirstAudioContent(offer->description());
1431 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1432 audio_content->description);
1433 EXPECT_FALSE(
1434 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1435
1436 video_content = cricket::GetFirstVideoContent(offer->description());
1437 video_desc = static_cast<const cricket::VideoContentDescription*>(
1438 video_content->description);
1439 EXPECT_FALSE(
1440 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1441
1442 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1443
1444 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1445 // should return false.
1446 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1447 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1448}
1449
1450// Test creating senders without a stream specified,
1451// expecting a random stream ID to be generated.
1452TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001453 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001454 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001455 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001456 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001457 rtc::scoped_refptr<VideoTrackInterface> video_track(
1458 pc_factory_->CreateVideoTrack(
1459 "video_track",
1460 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefe1f9d832016-01-14 15:35:42 -08001461 auto audio_sender =
1462 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1463 auto video_sender =
1464 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1465 EXPECT_EQ("audio_track", audio_sender->id());
1466 EXPECT_EQ(audio_track, audio_sender->track());
1467 EXPECT_EQ("video_track", video_sender->id());
1468 EXPECT_EQ(video_track, video_sender->track());
1469 // If the ID is truly a random GUID, it should be infinitely unlikely they
1470 // will be the same.
deadbeefa601f5c2016-06-06 14:27:39 -07001471 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
deadbeefe1f9d832016-01-14 15:35:42 -08001472}
1473
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1475 InitiateCall();
1476 WaitAndVerifyOnAddStream(kStreamLabel1);
1477 VerifyRemoteRtpHeaderExtensions();
1478}
1479
1480TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001481 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001482 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 CreateOfferAsLocalDescription();
1484 std::string offer;
1485 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1486 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1487 WaitAndVerifyOnAddStream(kStreamLabel1);
1488}
1489
1490TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001491 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001492 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493
1494 CreateOfferAsRemoteDescription();
1495 CreateAnswerAsLocalDescription();
1496
1497 WaitAndVerifyOnAddStream(kStreamLabel1);
1498}
1499
1500TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001501 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001502 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503
1504 CreateOfferAsRemoteDescription();
1505 CreatePrAnswerAsLocalDescription();
1506 CreateAnswerAsLocalDescription();
1507
1508 WaitAndVerifyOnAddStream(kStreamLabel1);
1509}
1510
1511TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1512 InitiateCall();
1513 ASSERT_EQ(1u, pc_->remote_streams()->count());
1514 pc_->RemoveStream(pc_->local_streams()->at(0));
1515 CreateOfferReceiveAnswer();
1516 EXPECT_EQ(0u, pc_->remote_streams()->count());
deadbeefab9b2d12015-10-14 11:33:11 -07001517 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 CreateOfferReceiveAnswer();
1519}
1520
1521// Tests that after negotiating an audio only call, the respondent can perform a
1522// renegotiation that removes the audio stream.
1523TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001524 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 AddVoiceStream(kStreamLabel1);
1526 CreateOfferAsRemoteDescription();
1527 CreateAnswerAsLocalDescription();
1528
1529 ASSERT_EQ(1u, pc_->remote_streams()->count());
1530 pc_->RemoveStream(pc_->local_streams()->at(0));
1531 CreateOfferReceiveAnswer();
1532 EXPECT_EQ(0u, pc_->remote_streams()->count());
1533}
1534
1535// Test that candidates are generated and that we can parse our own candidates.
1536TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001537 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538
1539 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1540 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001541 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefab9b2d12015-10-14 11:33:11 -07001542 AddVideoStream(kStreamLabel1);
deadbeefc80741f2015-10-22 13:14:45 -07001543 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001544 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545
1546 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001547 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001548 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001549 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550
1551 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1552 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1553
1554 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1555}
1556
deadbeefab9b2d12015-10-14 11:33:11 -07001557// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558// not unique.
1559TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001560 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001562 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001563 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001564 EXPECT_TRUE(offer);
1565 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566
1567 // Create a local stream with audio&video tracks having same label.
1568 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1569
1570 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001571 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572
1573 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001574 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001575 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576}
1577
1578// Test that we will get different SSRCs for each tracks in the offer and answer
1579// we created.
1580TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001581 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 // Create a local stream with audio&video tracks having different labels.
1583 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1584
1585 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001586 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001587 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 int audio_ssrc = 0;
1589 int video_ssrc = 0;
1590 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1591 &audio_ssrc));
1592 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1593 &video_ssrc));
1594 EXPECT_NE(audio_ssrc, video_ssrc);
1595
1596 // Test CreateAnswer
1597 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergd1fe2812016-04-27 06:47:29 -07001598 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001599 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 audio_ssrc = 0;
1601 video_ssrc = 0;
1602 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1603 &audio_ssrc));
1604 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1605 &video_ssrc));
1606 EXPECT_NE(audio_ssrc, video_ssrc);
1607}
1608
deadbeefeb459812015-12-15 19:24:43 -08001609// Test that it's possible to call AddTrack on a MediaStream after adding
1610// the stream to a PeerConnection.
1611// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1612TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001613 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001614 // Create audio stream and add to PeerConnection.
1615 AddVoiceStream(kStreamLabel1);
1616 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1617
1618 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001619 rtc::scoped_refptr<VideoTrackInterface> video_track(
1620 pc_factory_->CreateVideoTrack(
1621 "video_label",
1622 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefeb459812015-12-15 19:24:43 -08001623 stream->AddTrack(video_track.get());
1624
kwibergd1fe2812016-04-27 06:47:29 -07001625 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001626 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001627
1628 const cricket::MediaContentDescription* video_desc =
1629 cricket::GetFirstVideoContentDescription(offer->description());
1630 EXPECT_TRUE(video_desc != nullptr);
1631}
1632
1633// Test that it's possible to call RemoveTrack on a MediaStream after adding
1634// the stream to a PeerConnection.
1635// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1636TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001637 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001638 // Create audio/video stream and add to PeerConnection.
1639 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1640 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1641
1642 // Remove the video track.
1643 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1644
kwibergd1fe2812016-04-27 06:47:29 -07001645 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001646 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001647
1648 const cricket::MediaContentDescription* video_desc =
1649 cricket::GetFirstVideoContentDescription(offer->description());
1650 EXPECT_TRUE(video_desc == nullptr);
1651}
1652
deadbeefbd7d8f72015-12-18 16:58:44 -08001653// Test creating a sender with a stream ID, and ensure the ID is populated
1654// in the offer.
1655TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001656 CreatePeerConnectionWithoutDtls();
deadbeefbd7d8f72015-12-18 16:58:44 -08001657 pc_->CreateSender("video", kStreamLabel1);
1658
kwibergd1fe2812016-04-27 06:47:29 -07001659 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001660 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001661
1662 const cricket::MediaContentDescription* video_desc =
1663 cricket::GetFirstVideoContentDescription(offer->description());
1664 ASSERT_TRUE(video_desc != nullptr);
1665 ASSERT_EQ(1u, video_desc->streams().size());
1666 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1667}
1668
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669// Test that we can specify a certain track that we want statistics about.
1670TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1671 InitiateCall();
1672 ASSERT_LT(0u, pc_->remote_streams()->count());
1673 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001674 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1676 EXPECT_TRUE(DoGetStats(remote_audio));
1677
1678 // Remove the stream. Since we are sending to our selves the local
1679 // and the remote stream is the same.
1680 pc_->RemoveStream(pc_->local_streams()->at(0));
1681 // Do a re-negotiation.
1682 CreateOfferReceiveAnswer();
1683
1684 ASSERT_EQ(0u, pc_->remote_streams()->count());
1685
1686 // Test that we still can get statistics for the old track. Even if it is not
1687 // sent any longer.
1688 EXPECT_TRUE(DoGetStats(remote_audio));
1689}
1690
1691// Test that we can get stats on a video track.
1692TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1693 InitiateCall();
1694 ASSERT_LT(0u, pc_->remote_streams()->count());
1695 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001696 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1698 EXPECT_TRUE(DoGetStats(remote_video));
1699}
1700
1701// Test that we don't get statistics for an invalid track.
zhihuange9e94c32016-11-04 11:38:15 -07001702TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001704 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 pc_factory_->CreateAudioTrack("unknown track", NULL));
1706 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1707}
1708
1709// This test setup two RTP data channels in loop back.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 FakeConstraints constraints;
1712 constraints.SetAllowRtpDataChannels();
1713 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001714 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001716 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 pc_->CreateDataChannel("test2", NULL);
1718 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001719 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001721 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 new MockDataChannelObserver(data2));
1723
1724 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1725 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1726 std::string data_to_send1 = "testing testing";
1727 std::string data_to_send2 = "testing something else";
1728 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1729
1730 CreateOfferReceiveAnswer();
1731 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1732 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1733
1734 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1735 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1736 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1737 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1738
1739 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1740 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1741
1742 data1->Close();
1743 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1744 CreateOfferReceiveAnswer();
1745 EXPECT_FALSE(observer1->IsOpen());
1746 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1747 EXPECT_TRUE(observer2->IsOpen());
1748
1749 data_to_send2 = "testing something else again";
1750 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1751
1752 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1753}
1754
1755// This test verifies that sendnig binary data over RTP data channels should
1756// fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 FakeConstraints constraints;
1759 constraints.SetAllowRtpDataChannels();
1760 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001761 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001763 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 pc_->CreateDataChannel("test2", NULL);
1765 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001766 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001768 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 new MockDataChannelObserver(data2));
1770
1771 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1772 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1773
1774 CreateOfferReceiveAnswer();
1775 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1776 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1777
1778 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1779 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1780
jbaucheec21bd2016-03-20 06:15:43 -07001781 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1783}
1784
1785// This test setup a RTP data channels in loop back and test that a channel is
1786// opened even if the remote end answer with a zero SSRC.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 FakeConstraints constraints;
1789 constraints.SetAllowRtpDataChannels();
1790 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001791 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001793 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 new MockDataChannelObserver(data1));
1795
1796 CreateOfferReceiveAnswerWithoutSsrc();
1797
1798 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1799
1800 data1->Close();
1801 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1802 CreateOfferReceiveAnswerWithoutSsrc();
1803 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1804 EXPECT_FALSE(observer1->IsOpen());
1805}
1806
1807// This test that if a data channel is added in an answer a receive only channel
1808// channel is created.
1809TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1810 FakeConstraints constraints;
1811 constraints.SetAllowRtpDataChannels();
1812 CreatePeerConnection(&constraints);
1813
1814 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07001815 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 pc_->CreateDataChannel(offer_label, NULL);
1817
1818 CreateOfferAsLocalDescription();
1819
1820 // Replace the data channel label in the offer and apply it as an answer.
1821 std::string receive_label = "answer_channel";
1822 std::string sdp;
1823 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001824 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 receive_label.c_str(), receive_label.length(),
1826 &sdp);
1827 CreateAnswerAsRemoteDescription(sdp);
1828
1829 // Verify that a new incoming data channel has been created and that
1830 // it is open but can't we written to.
1831 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1832 DataChannelInterface* received_channel = observer_.last_datachannel_;
1833 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1834 EXPECT_EQ(receive_label, received_channel->label());
1835 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1836
1837 // Verify that the channel we initially offered has been rejected.
1838 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1839
1840 // Do another offer / answer exchange and verify that the data channel is
1841 // opened.
1842 CreateOfferReceiveAnswer();
1843 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1844 kTimeout);
1845}
1846
1847// This test that no data channel is returned if a reliable channel is
1848// requested.
1849// TODO(perkj): Remove this test once reliable channels are implemented.
1850TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1851 FakeConstraints constraints;
1852 constraints.SetAllowRtpDataChannels();
1853 CreatePeerConnection(&constraints);
1854
1855 std::string label = "test";
1856 webrtc::DataChannelInit config;
1857 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07001858 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 pc_->CreateDataChannel(label, &config);
1860 EXPECT_TRUE(channel == NULL);
1861}
1862
deadbeefab9b2d12015-10-14 11:33:11 -07001863// Verifies that duplicated label is not allowed for RTP data channel.
1864TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1865 FakeConstraints constraints;
1866 constraints.SetAllowRtpDataChannels();
1867 CreatePeerConnection(&constraints);
1868
1869 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001870 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001871 pc_->CreateDataChannel(label, nullptr);
1872 EXPECT_NE(channel, nullptr);
1873
zhihuang9763d562016-08-05 11:14:50 -07001874 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001875 pc_->CreateDataChannel(label, nullptr);
1876 EXPECT_EQ(dup_channel, nullptr);
1877}
1878
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879// This tests that a SCTP data channel is returned using different
1880// DataChannelInit configurations.
1881TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1882 FakeConstraints constraints;
1883 constraints.SetAllowDtlsSctpDataChannels();
1884 CreatePeerConnection(&constraints);
1885
1886 webrtc::DataChannelInit config;
1887
zhihuang9763d562016-08-05 11:14:50 -07001888 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889 pc_->CreateDataChannel("1", &config);
1890 EXPECT_TRUE(channel != NULL);
1891 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001892 EXPECT_TRUE(observer_.renegotiation_needed_);
1893 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894
1895 config.ordered = false;
1896 channel = pc_->CreateDataChannel("2", &config);
1897 EXPECT_TRUE(channel != NULL);
1898 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001899 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900
1901 config.ordered = true;
1902 config.maxRetransmits = 0;
1903 channel = pc_->CreateDataChannel("3", &config);
1904 EXPECT_TRUE(channel != NULL);
1905 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001906 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907
1908 config.maxRetransmits = -1;
1909 config.maxRetransmitTime = 0;
1910 channel = pc_->CreateDataChannel("4", &config);
1911 EXPECT_TRUE(channel != NULL);
1912 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001913 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914}
1915
1916// This tests that no data channel is returned if both maxRetransmits and
1917// maxRetransmitTime are set for SCTP data channels.
1918TEST_F(PeerConnectionInterfaceTest,
1919 CreateSctpDataChannelShouldFailForInvalidConfig) {
1920 FakeConstraints constraints;
1921 constraints.SetAllowDtlsSctpDataChannels();
1922 CreatePeerConnection(&constraints);
1923
1924 std::string label = "test";
1925 webrtc::DataChannelInit config;
1926 config.maxRetransmits = 0;
1927 config.maxRetransmitTime = 0;
1928
zhihuang9763d562016-08-05 11:14:50 -07001929 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 pc_->CreateDataChannel(label, &config);
1931 EXPECT_TRUE(channel == NULL);
1932}
1933
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934// The test verifies that creating a SCTP data channel with an id already in use
1935// or out of range should fail.
1936TEST_F(PeerConnectionInterfaceTest,
1937 CreateSctpDataChannelWithInvalidIdShouldFail) {
1938 FakeConstraints constraints;
1939 constraints.SetAllowDtlsSctpDataChannels();
1940 CreatePeerConnection(&constraints);
1941
1942 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07001943 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001944
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001945 config.id = 1;
1946 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 EXPECT_TRUE(channel != NULL);
1948 EXPECT_EQ(1, channel->id());
1949
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 channel = pc_->CreateDataChannel("x", &config);
1951 EXPECT_TRUE(channel == NULL);
1952
1953 config.id = cricket::kMaxSctpSid;
1954 channel = pc_->CreateDataChannel("max", &config);
1955 EXPECT_TRUE(channel != NULL);
1956 EXPECT_EQ(config.id, channel->id());
1957
1958 config.id = cricket::kMaxSctpSid + 1;
1959 channel = pc_->CreateDataChannel("x", &config);
1960 EXPECT_TRUE(channel == NULL);
1961}
1962
deadbeefab9b2d12015-10-14 11:33:11 -07001963// Verifies that duplicated label is allowed for SCTP data channel.
1964TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
1965 FakeConstraints constraints;
1966 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1967 true);
1968 CreatePeerConnection(&constraints);
1969
1970 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001971 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001972 pc_->CreateDataChannel(label, nullptr);
1973 EXPECT_NE(channel, nullptr);
1974
zhihuang9763d562016-08-05 11:14:50 -07001975 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001976 pc_->CreateDataChannel(label, nullptr);
1977 EXPECT_NE(dup_channel, nullptr);
1978}
1979
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001980// This test verifies that OnRenegotiationNeeded is fired for every new RTP
1981// DataChannel.
1982TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
1983 FakeConstraints constraints;
1984 constraints.SetAllowRtpDataChannels();
1985 CreatePeerConnection(&constraints);
1986
zhihuang9763d562016-08-05 11:14:50 -07001987 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001988 pc_->CreateDataChannel("test1", NULL);
1989 EXPECT_TRUE(observer_.renegotiation_needed_);
1990 observer_.renegotiation_needed_ = false;
1991
zhihuang9763d562016-08-05 11:14:50 -07001992 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001993 pc_->CreateDataChannel("test2", NULL);
1994 EXPECT_TRUE(observer_.renegotiation_needed_);
1995}
1996
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997// This test that a data channel closes when a PeerConnection is deleted/closed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 FakeConstraints constraints;
2000 constraints.SetAllowRtpDataChannels();
2001 CreatePeerConnection(&constraints);
2002
zhihuang9763d562016-08-05 11:14:50 -07002003 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002005 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 pc_->CreateDataChannel("test2", NULL);
2007 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002008 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002010 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011 new MockDataChannelObserver(data2));
2012
2013 CreateOfferReceiveAnswer();
2014 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2015 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2016
2017 ReleasePeerConnection();
2018 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2019 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2020}
2021
2022// This test that data channels can be rejected in an answer.
2023TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
2024 FakeConstraints constraints;
2025 constraints.SetAllowRtpDataChannels();
2026 CreatePeerConnection(&constraints);
2027
zhihuang9763d562016-08-05 11:14:50 -07002028 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 pc_->CreateDataChannel("offer_channel", NULL));
2030
2031 CreateOfferAsLocalDescription();
2032
2033 // Create an answer where the m-line for data channels are rejected.
2034 std::string sdp;
2035 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2036 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
2037 SessionDescriptionInterface::kAnswer);
2038 EXPECT_TRUE(answer->Initialize(sdp, NULL));
2039 cricket::ContentInfo* data_info =
2040 answer->description()->GetContentByName("data");
2041 data_info->rejected = true;
2042
2043 DoSetRemoteDescription(answer);
2044 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2045}
2046
2047// Test that we can create a session description from an SDP string from
2048// FireFox, use it as a remote session description, generate an answer and use
2049// the answer as a local description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002050TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 FakeConstraints constraints;
2052 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2053 true);
2054 CreatePeerConnection(&constraints);
2055 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2056 SessionDescriptionInterface* desc =
2057 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002058 webrtc::kFireFoxSdpOffer, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2060 CreateAnswerAsLocalDescription();
2061 ASSERT_TRUE(pc_->local_description() != NULL);
2062 ASSERT_TRUE(pc_->remote_description() != NULL);
2063
2064 const cricket::ContentInfo* content =
2065 cricket::GetFirstAudioContent(pc_->local_description()->description());
2066 ASSERT_TRUE(content != NULL);
2067 EXPECT_FALSE(content->rejected);
2068
2069 content =
2070 cricket::GetFirstVideoContent(pc_->local_description()->description());
2071 ASSERT_TRUE(content != NULL);
2072 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002073#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 content =
2075 cricket::GetFirstDataContent(pc_->local_description()->description());
2076 ASSERT_TRUE(content != NULL);
2077 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002078#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
deadbeef8662f942017-01-20 21:20:51 -08002081// Test that an offer can be received which offers DTLS with SDES fallback.
2082// Regression test for issue:
2083// https://bugs.chromium.org/p/webrtc/issues/detail?id=6972
2084TEST_F(PeerConnectionInterfaceTest, ReceiveDtlsSdesFallbackOffer) {
2085 FakeConstraints constraints;
2086 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2087 true);
2088 CreatePeerConnection(&constraints);
2089 // Wait for fake certificate to be generated. Previously, this is what caused
2090 // the "a=crypto" lines to be rejected.
2091 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2092 ASSERT_NE(nullptr, fake_certificate_generator_);
2093 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2094 kTimeout);
2095 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
2096 SessionDescriptionInterface::kOffer, kDtlsSdesFallbackSdp, nullptr);
2097 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2098 CreateAnswerAsLocalDescription();
2099}
2100
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101// Test that we can create an audio only offer and receive an answer with a
2102// limited set of audio codecs and receive an updated offer with more audio
2103// codecs, where the added codecs are not supported.
2104TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002105 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 AddVoiceStream("audio_label");
2107 CreateOfferAsLocalDescription();
2108
2109 SessionDescriptionInterface* answer =
2110 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
jbauchfabe2c92015-07-16 13:43:14 -07002111 webrtc::kAudioSdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 EXPECT_TRUE(DoSetSessionDescription(answer, false));
2113
2114 SessionDescriptionInterface* updated_offer =
2115 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002116 webrtc::kAudioSdpWithUnsupportedCodecs,
2117 nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
2119 CreateAnswerAsLocalDescription();
2120}
2121
deadbeefc80741f2015-10-22 13:14:45 -07002122// Test that if we're receiving (but not sending) a track, subsequent offers
2123// will have m-lines with a=recvonly.
2124TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2125 FakeConstraints constraints;
2126 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2127 true);
2128 CreatePeerConnection(&constraints);
2129 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2130 CreateAnswerAsLocalDescription();
2131
2132 // At this point we should be receiving stream 1, but not sending anything.
2133 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002134 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002135 DoCreateOffer(&offer, nullptr);
2136
2137 const cricket::ContentInfo* video_content =
2138 cricket::GetFirstVideoContent(offer->description());
2139 const cricket::VideoContentDescription* video_desc =
2140 static_cast<const cricket::VideoContentDescription*>(
2141 video_content->description);
2142 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
2143
2144 const cricket::ContentInfo* audio_content =
2145 cricket::GetFirstAudioContent(offer->description());
2146 const cricket::AudioContentDescription* audio_desc =
2147 static_cast<const cricket::AudioContentDescription*>(
2148 audio_content->description);
2149 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
2150}
2151
2152// Test that if we're receiving (but not sending) a track, and the
2153// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2154// false, the generated m-lines will be a=inactive.
2155TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2156 FakeConstraints constraints;
2157 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2158 true);
2159 CreatePeerConnection(&constraints);
2160 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2161 CreateAnswerAsLocalDescription();
2162
2163 // At this point we should be receiving stream 1, but not sending anything.
2164 // A new offer would be recvonly, but we'll set the "no receive" constraints
2165 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002166 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002167 FakeConstraints offer_constraints;
2168 offer_constraints.AddMandatory(
2169 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2170 offer_constraints.AddMandatory(
2171 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2172 DoCreateOffer(&offer, &offer_constraints);
2173
2174 const cricket::ContentInfo* video_content =
2175 cricket::GetFirstVideoContent(offer->description());
2176 const cricket::VideoContentDescription* video_desc =
2177 static_cast<const cricket::VideoContentDescription*>(
2178 video_content->description);
2179 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
2180
2181 const cricket::ContentInfo* audio_content =
2182 cricket::GetFirstAudioContent(offer->description());
2183 const cricket::AudioContentDescription* audio_desc =
2184 static_cast<const cricket::AudioContentDescription*>(
2185 audio_content->description);
2186 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
2187}
2188
deadbeef653b8e02015-11-11 12:55:10 -08002189// Test that we can use SetConfiguration to change the ICE servers of the
2190// PortAllocator.
2191TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2192 CreatePeerConnection();
2193
2194 PeerConnectionInterface::RTCConfiguration config;
2195 PeerConnectionInterface::IceServer server;
2196 server.uri = "stun:test_hostname";
2197 config.servers.push_back(server);
2198 EXPECT_TRUE(pc_->SetConfiguration(config));
2199
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002200 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2201 EXPECT_EQ("test_hostname",
2202 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002203}
2204
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002205TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2206 CreatePeerConnection();
2207 PeerConnectionInterface::RTCConfiguration config;
2208 config.type = PeerConnectionInterface::kRelay;
2209 EXPECT_TRUE(pc_->SetConfiguration(config));
2210 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2211}
2212
deadbeef293e9262017-01-11 12:28:30 -08002213TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
2214 PeerConnectionInterface::RTCConfiguration config;
2215 config.prune_turn_ports = false;
2216 CreatePeerConnection(config, nullptr);
2217 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2218
2219 config.prune_turn_ports = true;
2220 EXPECT_TRUE(pc_->SetConfiguration(config));
2221 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2222}
2223
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002224// Test that when SetConfiguration changes both the pool size and other
2225// attributes, the pooled session is created with the updated attributes.
2226TEST_F(PeerConnectionInterfaceTest,
2227 SetConfigurationCreatesPooledSessionCorrectly) {
2228 CreatePeerConnection();
2229 PeerConnectionInterface::RTCConfiguration config;
2230 config.ice_candidate_pool_size = 1;
2231 PeerConnectionInterface::IceServer server;
2232 server.uri = kStunAddressOnly;
2233 config.servers.push_back(server);
2234 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002235 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002236
2237 const cricket::FakePortAllocatorSession* session =
2238 static_cast<const cricket::FakePortAllocatorSession*>(
2239 port_allocator_->GetPooledSession());
2240 ASSERT_NE(nullptr, session);
2241 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002242}
2243
deadbeef293e9262017-01-11 12:28:30 -08002244// Test that after SetLocalDescription, changing the pool size is not allowed,
2245// and an invalid modification error is returned.
deadbeef6de92f92016-12-12 18:49:32 -08002246TEST_F(PeerConnectionInterfaceTest,
2247 CantChangePoolSizeAfterSetLocalDescription) {
2248 CreatePeerConnection();
2249 // Start by setting a size of 1.
2250 PeerConnectionInterface::RTCConfiguration config;
2251 config.ice_candidate_pool_size = 1;
2252 EXPECT_TRUE(pc_->SetConfiguration(config));
2253
2254 // Set remote offer; can still change pool size at this point.
2255 CreateOfferAsRemoteDescription();
2256 config.ice_candidate_pool_size = 2;
2257 EXPECT_TRUE(pc_->SetConfiguration(config));
2258
2259 // Set local answer; now it's too late.
2260 CreateAnswerAsLocalDescription();
2261 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002262 RTCError error;
2263 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2264 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2265}
2266
2267// Test that SetConfiguration returns an invalid modification error if
2268// modifying a field in the configuration that isn't allowed to be modified.
2269TEST_F(PeerConnectionInterfaceTest,
2270 SetConfigurationReturnsInvalidModificationError) {
2271 PeerConnectionInterface::RTCConfiguration config;
2272 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2273 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2274 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2275 CreatePeerConnection(config, nullptr);
2276
2277 PeerConnectionInterface::RTCConfiguration modified_config = config;
2278 modified_config.bundle_policy =
2279 PeerConnectionInterface::kBundlePolicyMaxBundle;
2280 RTCError error;
2281 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2282 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2283
2284 modified_config = config;
2285 modified_config.rtcp_mux_policy =
2286 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2287 error.set_type(RTCErrorType::NONE);
2288 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2289 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2290
2291 modified_config = config;
2292 modified_config.continual_gathering_policy =
2293 PeerConnectionInterface::GATHER_CONTINUALLY;
2294 error.set_type(RTCErrorType::NONE);
2295 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2296 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2297}
2298
2299// Test that SetConfiguration returns a range error if the candidate pool size
2300// is negative or larger than allowed by the spec.
2301TEST_F(PeerConnectionInterfaceTest,
2302 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2303 PeerConnectionInterface::RTCConfiguration config;
2304 CreatePeerConnection(config, nullptr);
2305
2306 config.ice_candidate_pool_size = -1;
2307 RTCError error;
2308 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2309 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2310
2311 config.ice_candidate_pool_size = INT_MAX;
2312 error.set_type(RTCErrorType::NONE);
2313 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2314 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2315}
2316
2317// Test that SetConfiguration returns a syntax error if parsing an ICE server
2318// URL failed.
2319TEST_F(PeerConnectionInterfaceTest,
2320 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2321 PeerConnectionInterface::RTCConfiguration config;
2322 CreatePeerConnection(config, nullptr);
2323
2324 PeerConnectionInterface::IceServer bad_server;
2325 bad_server.uri = "stunn:www.example.com";
2326 config.servers.push_back(bad_server);
2327 RTCError error;
2328 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2329 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2330}
2331
2332// Test that SetConfiguration returns an invalid parameter error if a TURN
2333// IceServer is missing a username or password.
2334TEST_F(PeerConnectionInterfaceTest,
2335 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2336 PeerConnectionInterface::RTCConfiguration config;
2337 CreatePeerConnection(config, nullptr);
2338
2339 PeerConnectionInterface::IceServer bad_server;
2340 bad_server.uri = "turn:www.example.com";
2341 // Missing password.
2342 bad_server.username = "foo";
2343 config.servers.push_back(bad_server);
2344 RTCError error;
2345 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2346 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002347}
2348
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349// Test that PeerConnection::Close changes the states to closed and all remote
2350// tracks change state to ended.
2351TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2352 // Initialize a PeerConnection and negotiate local and remote session
2353 // description.
2354 InitiateCall();
2355 ASSERT_EQ(1u, pc_->local_streams()->count());
2356 ASSERT_EQ(1u, pc_->remote_streams()->count());
2357
2358 pc_->Close();
2359
2360 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2361 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2362 pc_->ice_connection_state());
2363 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2364 pc_->ice_gathering_state());
2365
2366 EXPECT_EQ(1u, pc_->local_streams()->count());
2367 EXPECT_EQ(1u, pc_->remote_streams()->count());
2368
zhihuang9763d562016-08-05 11:14:50 -07002369 rtc::scoped_refptr<MediaStreamInterface> remote_stream =
2370 pc_->remote_streams()->at(0);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002371 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002372 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002373 remote_stream->GetAudioTracks()[0]->state(), kTimeout);
2374 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2375 remote_stream->GetVideoTracks()[0]->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376}
2377
2378// Test that PeerConnection methods fails gracefully after
2379// PeerConnection::Close has been called.
2380TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002381 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2383 CreateOfferAsRemoteDescription();
2384 CreateAnswerAsLocalDescription();
2385
2386 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002387 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 pc_->local_streams()->at(0);
2389
2390 pc_->Close();
2391
2392 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002393 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394
2395 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002396 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002398 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399
2400 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2401
2402 EXPECT_TRUE(pc_->local_description() != NULL);
2403 EXPECT_TRUE(pc_->remote_description() != NULL);
2404
kwibergd1fe2812016-04-27 06:47:29 -07002405 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07002406 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002407 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07002408 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409
2410 std::string sdp;
2411 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2412 SessionDescriptionInterface* remote_offer =
2413 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2414 sdp, NULL);
2415 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
2416
2417 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2418 SessionDescriptionInterface* local_offer =
2419 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2420 sdp, NULL);
2421 EXPECT_FALSE(DoSetLocalDescription(local_offer));
2422}
2423
2424// Test that GetStats can still be called after PeerConnection::Close.
2425TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
2426 InitiateCall();
2427 pc_->Close();
2428 DoGetStats(NULL);
2429}
deadbeefab9b2d12015-10-14 11:33:11 -07002430
2431// NOTE: The series of tests below come from what used to be
2432// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2433// setting a remote or local description has the expected effects.
2434
2435// This test verifies that the remote MediaStreams corresponding to a received
2436// SDP string is created. In this test the two separate MediaStreams are
2437// signaled.
2438TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2439 FakeConstraints constraints;
2440 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2441 true);
2442 CreatePeerConnection(&constraints);
2443 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2444
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002445 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002446 EXPECT_TRUE(
2447 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2448 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2449 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2450
2451 // Create a session description based on another SDP with another
2452 // MediaStream.
2453 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
2454
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002455 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002456 EXPECT_TRUE(
2457 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2458}
2459
2460// This test verifies that when remote tracks are added/removed from SDP, the
2461// created remote streams are updated appropriately.
2462TEST_F(PeerConnectionInterfaceTest,
2463 AddRemoveTrackFromExistingRemoteMediaStream) {
2464 FakeConstraints constraints;
2465 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2466 true);
2467 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002468 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002469 CreateSessionDescriptionAndReference(1, 1);
deadbeefab9b2d12015-10-14 11:33:11 -07002470 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
2471 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2472 reference_collection_));
2473
2474 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002475 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002476 CreateSessionDescriptionAndReference(2, 2);
deadbeefab9b2d12015-10-14 11:33:11 -07002477 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
2478 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2479 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002480 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002481 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2482 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002483 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002484 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2485 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002486
2487 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002488 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002489 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002490 MockTrackObserver audio_track_observer(audio_track2);
2491 MockTrackObserver video_track_observer(video_track2);
2492
2493 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2494 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
deadbeefab9b2d12015-10-14 11:33:11 -07002495 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
2496 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2497 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002498 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002499 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002500 audio_track2->state(), kTimeout);
2501 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2502 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002503}
2504
2505// This tests that remote tracks are ended if a local session description is set
2506// that rejects the media content type.
2507TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
2508 FakeConstraints constraints;
2509 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2510 true);
2511 CreatePeerConnection(&constraints);
2512 // First create and set a remote offer, then reject its video content in our
2513 // answer.
2514 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2515 ASSERT_EQ(1u, observer_.remote_streams()->count());
2516 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2517 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2518 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2519
2520 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
2521 remote_stream->GetVideoTracks()[0];
2522 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
2523 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
2524 remote_stream->GetAudioTracks()[0];
2525 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2526
kwibergd1fe2812016-04-27 06:47:29 -07002527 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002528 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002529 cricket::ContentInfo* video_info =
2530 local_answer->description()->GetContentByName("video");
2531 video_info->rejected = true;
2532 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2533 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2534 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2535
2536 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002537 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002538 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002539 video_info = local_offer->description()->GetContentByName("video");
2540 ASSERT_TRUE(video_info != nullptr);
2541 video_info->rejected = true;
2542 cricket::ContentInfo* audio_info =
2543 local_offer->description()->GetContentByName("audio");
2544 ASSERT_TRUE(audio_info != nullptr);
2545 audio_info->rejected = true;
2546 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002547 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002548 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002549 remote_audio->state(), kTimeout);
2550 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2551 remote_video->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002552}
2553
2554// This tests that we won't crash if the remote track has been removed outside
2555// of PeerConnection and then PeerConnection tries to reject the track.
2556TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2557 FakeConstraints constraints;
2558 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2559 true);
2560 CreatePeerConnection(&constraints);
2561 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2562 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2563 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2564 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2565
kwibergd1fe2812016-04-27 06:47:29 -07002566 std::unique_ptr<SessionDescriptionInterface> local_answer(
deadbeefab9b2d12015-10-14 11:33:11 -07002567 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2568 kSdpStringWithStream1, nullptr));
2569 cricket::ContentInfo* video_info =
2570 local_answer->description()->GetContentByName("video");
2571 video_info->rejected = true;
2572 cricket::ContentInfo* audio_info =
2573 local_answer->description()->GetContentByName("audio");
2574 audio_info->rejected = true;
2575 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2576
2577 // No crash is a pass.
2578}
2579
deadbeef5e97fb52015-10-15 12:49:08 -07002580// This tests that if a recvonly remote description is set, no remote streams
2581// will be created, even if the description contains SSRCs/MSIDs.
2582// See: https://code.google.com/p/webrtc/issues/detail?id=5054
2583TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2584 FakeConstraints constraints;
2585 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2586 true);
2587 CreatePeerConnection(&constraints);
2588
2589 std::string recvonly_offer = kSdpStringWithStream1;
2590 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2591 strlen(kRecvonly), &recvonly_offer);
2592 CreateAndSetRemoteOffer(recvonly_offer);
2593
2594 EXPECT_EQ(0u, observer_.remote_streams()->count());
2595}
2596
deadbeefab9b2d12015-10-14 11:33:11 -07002597// This tests that a default MediaStream is created if a remote session
2598// description doesn't contain any streams and no MSID support.
2599// It also tests that the default stream is updated if a video m-line is added
2600// in a subsequent session description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002601TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002602 FakeConstraints constraints;
2603 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2604 true);
2605 CreatePeerConnection(&constraints);
2606 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2607
2608 ASSERT_EQ(1u, observer_.remote_streams()->count());
2609 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2610
2611 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2612 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2613 EXPECT_EQ("default", remote_stream->label());
2614
2615 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2616 ASSERT_EQ(1u, observer_.remote_streams()->count());
2617 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2618 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002619 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2620 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002621 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2622 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002623 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2624 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002625}
2626
2627// This tests that a default MediaStream is created if a remote session
2628// description doesn't contain any streams and media direction is send only.
2629TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002630 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002631 FakeConstraints constraints;
2632 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2633 true);
2634 CreatePeerConnection(&constraints);
2635 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2636
2637 ASSERT_EQ(1u, observer_.remote_streams()->count());
2638 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2639
2640 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2641 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2642 EXPECT_EQ("default", remote_stream->label());
2643}
2644
2645// This tests that it won't crash when PeerConnection tries to remove
2646// a remote track that as already been removed from the MediaStream.
2647TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2648 FakeConstraints constraints;
2649 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2650 true);
2651 CreatePeerConnection(&constraints);
2652 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2653 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2654 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2655 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2656
2657 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2658
2659 // No crash is a pass.
2660}
2661
2662// This tests that a default MediaStream is created if the remote session
2663// description doesn't contain any streams and don't contain an indication if
2664// MSID is supported.
2665TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002666 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002667 FakeConstraints constraints;
2668 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2669 true);
2670 CreatePeerConnection(&constraints);
2671 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2672
2673 ASSERT_EQ(1u, observer_.remote_streams()->count());
2674 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2675 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2676 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2677}
2678
2679// This tests that a default MediaStream is not created if the remote session
2680// description doesn't contain any streams but does support MSID.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002681TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002682 FakeConstraints constraints;
2683 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2684 true);
2685 CreatePeerConnection(&constraints);
2686 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2687 EXPECT_EQ(0u, observer_.remote_streams()->count());
2688}
2689
deadbeefbda7e0b2015-12-08 17:13:40 -08002690// This tests that when setting a new description, the old default tracks are
2691// not destroyed and recreated.
2692// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Stefan Holmer102362b2016-03-18 09:39:07 +01002693TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002694 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08002695 FakeConstraints constraints;
2696 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2697 true);
2698 CreatePeerConnection(&constraints);
2699 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2700
2701 ASSERT_EQ(1u, observer_.remote_streams()->count());
2702 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2703 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2704
2705 // Set the track to "disabled", then set a new description and ensure the
2706 // track is still disabled, which ensures it hasn't been recreated.
2707 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2708 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2709 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2710 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2711}
2712
deadbeefab9b2d12015-10-14 11:33:11 -07002713// This tests that a default MediaStream is not created if a remote session
2714// description is updated to not have any MediaStreams.
2715TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2716 FakeConstraints constraints;
2717 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2718 true);
2719 CreatePeerConnection(&constraints);
2720 CreateAndSetRemoteOffer(kSdpStringWithStream1);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002721 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002722 EXPECT_TRUE(
2723 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2724
2725 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2726 EXPECT_EQ(0u, observer_.remote_streams()->count());
2727}
2728
2729// This tests that an RtpSender is created when the local description is set
2730// after adding a local stream.
2731// TODO(deadbeef): This test and the one below it need to be updated when
2732// an RtpSender's lifetime isn't determined by when a local description is set.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002733TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002734 FakeConstraints constraints;
2735 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2736 true);
2737 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002738
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002739 // Create an offer with 1 stream with 2 tracks of each type.
2740 rtc::scoped_refptr<StreamCollection> stream_collection =
2741 CreateStreamCollection(1, 2);
2742 pc_->AddStream(stream_collection->at(0));
2743 std::unique_ptr<SessionDescriptionInterface> offer;
2744 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2745 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002746
deadbeefab9b2d12015-10-14 11:33:11 -07002747 auto senders = pc_->GetSenders();
2748 EXPECT_EQ(4u, senders.size());
2749 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2750 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2751 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2752 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2753
2754 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002755 pc_->RemoveStream(stream_collection->at(0));
2756 stream_collection = CreateStreamCollection(1, 1);
2757 pc_->AddStream(stream_collection->at(0));
2758 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2759 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2760
deadbeefab9b2d12015-10-14 11:33:11 -07002761 senders = pc_->GetSenders();
2762 EXPECT_EQ(2u, senders.size());
2763 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2764 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2765 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2766 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2767}
2768
2769// This tests that an RtpSender is created when the local description is set
2770// before adding a local stream.
2771TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002772 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002773 FakeConstraints constraints;
2774 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2775 true);
2776 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002777
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002778 rtc::scoped_refptr<StreamCollection> stream_collection =
2779 CreateStreamCollection(1, 2);
2780 // Add a stream to create the offer, but remove it afterwards.
2781 pc_->AddStream(stream_collection->at(0));
2782 std::unique_ptr<SessionDescriptionInterface> offer;
2783 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2784 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002785
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002786 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002787 auto senders = pc_->GetSenders();
2788 EXPECT_EQ(0u, senders.size());
2789
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002790 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002791 senders = pc_->GetSenders();
2792 EXPECT_EQ(4u, senders.size());
2793 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2794 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2795 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2796 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2797}
2798
2799// This tests that the expected behavior occurs if the SSRC on a local track is
2800// changed when SetLocalDescription is called.
2801TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002802 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07002803 FakeConstraints constraints;
2804 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2805 true);
2806 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002807
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002808 rtc::scoped_refptr<StreamCollection> stream_collection =
2809 CreateStreamCollection(2, 1);
2810 pc_->AddStream(stream_collection->at(0));
2811 std::unique_ptr<SessionDescriptionInterface> offer;
2812 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2813 // Grab a copy of the offer before it gets passed into the PC.
2814 std::unique_ptr<JsepSessionDescription> modified_offer(
2815 new JsepSessionDescription(JsepSessionDescription::kOffer));
2816 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
2817 offer->session_version());
2818 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002819
deadbeefab9b2d12015-10-14 11:33:11 -07002820 auto senders = pc_->GetSenders();
2821 EXPECT_EQ(2u, senders.size());
2822 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2823 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2824
2825 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002826 cricket::MediaContentDescription* desc =
2827 cricket::GetFirstAudioContentDescription(modified_offer->description());
2828 ASSERT_TRUE(desc != NULL);
2829 for (StreamParams& stream : desc->mutable_streams()) {
2830 for (unsigned int& ssrc : stream.ssrcs) {
2831 ++ssrc;
2832 }
2833 }
deadbeefab9b2d12015-10-14 11:33:11 -07002834
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002835 desc =
2836 cricket::GetFirstVideoContentDescription(modified_offer->description());
2837 ASSERT_TRUE(desc != NULL);
2838 for (StreamParams& stream : desc->mutable_streams()) {
2839 for (unsigned int& ssrc : stream.ssrcs) {
2840 ++ssrc;
2841 }
2842 }
2843
2844 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002845 senders = pc_->GetSenders();
2846 EXPECT_EQ(2u, senders.size());
2847 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2848 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2849 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2850 // changed.
2851}
2852
2853// This tests that the expected behavior occurs if a new session description is
2854// set with the same tracks, but on a different MediaStream.
Stefan Holmer55d6e7c2016-03-17 16:26:40 +01002855TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002856 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002857 FakeConstraints constraints;
2858 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2859 true);
2860 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002861
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002862 rtc::scoped_refptr<StreamCollection> stream_collection =
2863 CreateStreamCollection(2, 1);
2864 pc_->AddStream(stream_collection->at(0));
2865 std::unique_ptr<SessionDescriptionInterface> offer;
2866 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2867 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002868
deadbeefab9b2d12015-10-14 11:33:11 -07002869 auto senders = pc_->GetSenders();
2870 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002871 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2872 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002873
2874 // Add a new MediaStream but with the same tracks as in the first stream.
2875 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2876 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002877 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2878 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002879 pc_->AddStream(stream_1);
2880
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002881 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2882 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002883
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002884 auto new_senders = pc_->GetSenders();
2885 // Should be the same senders as before, but with updated stream id.
2886 // Note that this behavior is subject to change in the future.
2887 // We may decide the PC should ignore existing tracks in AddStream.
2888 EXPECT_EQ(senders, new_senders);
2889 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2890 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002891}
2892
zhihuang81c3a032016-11-17 12:06:24 -08002893// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
2894TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) {
2895 FakeConstraints constraints;
2896 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2897 true);
2898 CreatePeerConnection(&constraints);
2899 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2900 EXPECT_EQ(observer_.num_added_tracks_, 1);
2901 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2902
2903 // Create and set the updated remote SDP.
2904 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2905 EXPECT_EQ(observer_.num_added_tracks_, 2);
2906 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2907}
2908
deadbeefd1a38b52016-12-10 13:15:33 -08002909// Test that when SetConfiguration is called and the configuration is
2910// changing, the next offer causes an ICE restart.
2911TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingIceRetart) {
2912 PeerConnectionInterface::RTCConfiguration config;
2913 config.type = PeerConnectionInterface::kRelay;
2914 // Need to pass default constraints to prevent disabling of DTLS...
2915 FakeConstraints default_constraints;
2916 CreatePeerConnection(config, &default_constraints);
2917 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2918
2919 // Do initial offer/answer so there's something to restart.
2920 CreateOfferAsLocalDescription();
2921 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2922
2923 // Grab the ufrags.
2924 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2925
2926 // Change ICE policy, which should trigger an ICE restart on the next offer.
2927 config.type = PeerConnectionInterface::kAll;
2928 EXPECT_TRUE(pc_->SetConfiguration(config));
2929 CreateOfferAsLocalDescription();
2930
2931 // Grab the new ufrags.
2932 std::vector<std::string> subsequent_ufrags =
2933 GetUfrags(pc_->local_description());
2934
2935 // Sanity check.
2936 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
2937 // Check that each ufrag is different.
2938 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
2939 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
2940 }
2941}
2942
2943// Test that when SetConfiguration is called and the configuration *isn't*
2944// changing, the next offer does *not* cause an ICE restart.
2945TEST_F(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRetart) {
2946 PeerConnectionInterface::RTCConfiguration config;
2947 config.type = PeerConnectionInterface::kRelay;
2948 // Need to pass default constraints to prevent disabling of DTLS...
2949 FakeConstraints default_constraints;
2950 CreatePeerConnection(config, &default_constraints);
2951 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2952
2953 // Do initial offer/answer so there's something to restart.
2954 CreateOfferAsLocalDescription();
2955 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2956
2957 // Grab the ufrags.
2958 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2959
2960 // Call SetConfiguration with a config identical to what the PC was
2961 // constructed with.
2962 EXPECT_TRUE(pc_->SetConfiguration(config));
2963 CreateOfferAsLocalDescription();
2964
2965 // Grab the new ufrags.
2966 std::vector<std::string> subsequent_ufrags =
2967 GetUfrags(pc_->local_description());
2968
2969 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
2970}
2971
2972// Test for a weird corner case scenario:
2973// 1. Audio/video session established.
2974// 2. SetConfiguration changes ICE config; ICE restart needed.
2975// 3. ICE restart initiated by remote peer, but only for one m= section.
2976// 4. Next createOffer should initiate an ICE restart, but only for the other
2977// m= section; it would be pointless to do an ICE restart for the m= section
2978// that was already restarted.
2979TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
2980 PeerConnectionInterface::RTCConfiguration config;
2981 config.type = PeerConnectionInterface::kRelay;
2982 // Need to pass default constraints to prevent disabling of DTLS...
2983 FakeConstraints default_constraints;
2984 CreatePeerConnection(config, &default_constraints);
2985 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2986
2987 // Do initial offer/answer so there's something to restart.
2988 CreateOfferAsLocalDescription();
2989 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2990
2991 // Change ICE policy, which should set the "needs-ice-restart" flag.
2992 config.type = PeerConnectionInterface::kAll;
2993 EXPECT_TRUE(pc_->SetConfiguration(config));
2994
2995 // Do ICE restart for the first m= section, initiated by remote peer.
2996 webrtc::JsepSessionDescription* remote_offer =
2997 new webrtc::JsepSessionDescription(SessionDescriptionInterface::kOffer);
2998 EXPECT_TRUE(remote_offer->Initialize(kSdpStringWithStream1, nullptr));
2999 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3000 "modified";
3001 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3002 CreateAnswerAsLocalDescription();
3003
3004 // Grab the ufrags.
3005 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3006 ASSERT_EQ(2, initial_ufrags.size());
3007
3008 // Create offer and grab the new ufrags.
3009 CreateOfferAsLocalDescription();
3010 std::vector<std::string> subsequent_ufrags =
3011 GetUfrags(pc_->local_description());
3012 ASSERT_EQ(2, subsequent_ufrags.size());
3013
3014 // Ensure that only the ufrag for the second m= section changed.
3015 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3016 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3017}
3018
deadbeeffe4a8a42016-12-20 17:56:17 -08003019// Tests that the methods to return current/pending descriptions work as
3020// expected at different points in the offer/answer exchange. This test does
3021// one offer/answer exchange as the offerer, then another as the answerer.
3022TEST_F(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
3023 // This disables DTLS so we can apply an answer to ourselves.
3024 CreatePeerConnection();
3025
3026 // Create initial local offer and get SDP (which will also be used as
3027 // answer/pranswer);
3028 std::unique_ptr<SessionDescriptionInterface> offer;
3029 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3030 std::string sdp;
3031 EXPECT_TRUE(offer->ToString(&sdp));
3032
3033 // Set local offer.
3034 SessionDescriptionInterface* local_offer = offer.release();
3035 EXPECT_TRUE(DoSetLocalDescription(local_offer));
3036 EXPECT_EQ(local_offer, pc_->pending_local_description());
3037 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3038 EXPECT_EQ(nullptr, pc_->current_local_description());
3039 EXPECT_EQ(nullptr, pc_->current_remote_description());
3040
3041 // Set remote pranswer.
3042 SessionDescriptionInterface* remote_pranswer =
3043 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3044 sdp, nullptr);
3045 EXPECT_TRUE(DoSetRemoteDescription(remote_pranswer));
3046 EXPECT_EQ(local_offer, pc_->pending_local_description());
3047 EXPECT_EQ(remote_pranswer, pc_->pending_remote_description());
3048 EXPECT_EQ(nullptr, pc_->current_local_description());
3049 EXPECT_EQ(nullptr, pc_->current_remote_description());
3050
3051 // Set remote answer.
3052 SessionDescriptionInterface* remote_answer = webrtc::CreateSessionDescription(
3053 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3054 EXPECT_TRUE(DoSetRemoteDescription(remote_answer));
3055 EXPECT_EQ(nullptr, pc_->pending_local_description());
3056 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3057 EXPECT_EQ(local_offer, pc_->current_local_description());
3058 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3059
3060 // Set remote offer.
3061 SessionDescriptionInterface* remote_offer = webrtc::CreateSessionDescription(
3062 SessionDescriptionInterface::kOffer, sdp, nullptr);
3063 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3064 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3065 EXPECT_EQ(nullptr, pc_->pending_local_description());
3066 EXPECT_EQ(local_offer, pc_->current_local_description());
3067 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3068
3069 // Set local pranswer.
3070 SessionDescriptionInterface* local_pranswer =
3071 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3072 sdp, nullptr);
3073 EXPECT_TRUE(DoSetLocalDescription(local_pranswer));
3074 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3075 EXPECT_EQ(local_pranswer, pc_->pending_local_description());
3076 EXPECT_EQ(local_offer, pc_->current_local_description());
3077 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3078
3079 // Set local answer.
3080 SessionDescriptionInterface* local_answer = webrtc::CreateSessionDescription(
3081 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3082 EXPECT_TRUE(DoSetLocalDescription(local_answer));
3083 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3084 EXPECT_EQ(nullptr, pc_->pending_local_description());
3085 EXPECT_EQ(remote_offer, pc_->current_remote_description());
3086 EXPECT_EQ(local_answer, pc_->current_local_description());
3087}
3088
nisse51542be2016-02-12 02:27:06 -08003089class PeerConnectionMediaConfigTest : public testing::Test {
3090 protected:
3091 void SetUp() override {
nisseaf510af2016-03-21 08:20:42 -07003092 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
nisse51542be2016-02-12 02:27:06 -08003093 pcf_->Initialize();
3094 }
3095 const cricket::MediaConfig& TestCreatePeerConnection(
3096 const PeerConnectionInterface::RTCConfiguration& config,
3097 const MediaConstraintsInterface *constraints) {
3098 pcf_->create_media_controller_called_ = false;
3099
zhihuang9763d562016-08-05 11:14:50 -07003100 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3101 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003102 EXPECT_TRUE(pc.get());
3103 EXPECT_TRUE(pcf_->create_media_controller_called_);
3104 return pcf_->create_media_controller_config_;
3105 }
3106
zhihuang9763d562016-08-05 11:14:50 -07003107 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003108 MockPeerConnectionObserver observer_;
3109};
3110
3111// This test verifies the default behaviour with no constraints and a
3112// default RTCConfiguration.
3113TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3114 PeerConnectionInterface::RTCConfiguration config;
3115 FakeConstraints constraints;
3116
3117 const cricket::MediaConfig& media_config =
3118 TestCreatePeerConnection(config, &constraints);
3119
3120 EXPECT_FALSE(media_config.enable_dscp);
nisse0db023a2016-03-01 04:29:59 -08003121 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection);
3122 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing);
3123 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003124}
3125
3126// This test verifies the DSCP constraint is recognized and passed to
3127// the CreateMediaController call.
3128TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
3129 PeerConnectionInterface::RTCConfiguration config;
3130 FakeConstraints constraints;
3131
3132 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
3133 const cricket::MediaConfig& media_config =
3134 TestCreatePeerConnection(config, &constraints);
3135
3136 EXPECT_TRUE(media_config.enable_dscp);
3137}
3138
3139// This test verifies the cpu overuse detection constraint is
3140// recognized and passed to the CreateMediaController call.
3141TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
3142 PeerConnectionInterface::RTCConfiguration config;
3143 FakeConstraints constraints;
3144
3145 constraints.AddOptional(
3146 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
3147 const cricket::MediaConfig media_config =
3148 TestCreatePeerConnection(config, &constraints);
3149
nisse0db023a2016-03-01 04:29:59 -08003150 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection);
nisse51542be2016-02-12 02:27:06 -08003151}
3152
3153// This test verifies that the disable_prerenderer_smoothing flag is
3154// propagated from RTCConfiguration to the CreateMediaController call.
3155TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3156 PeerConnectionInterface::RTCConfiguration config;
3157 FakeConstraints constraints;
3158
Niels Möller71bdda02016-03-31 12:59:59 +02003159 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08003160 const cricket::MediaConfig& media_config =
3161 TestCreatePeerConnection(config, &constraints);
3162
nisse0db023a2016-03-01 04:29:59 -08003163 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing);
3164}
3165
3166// This test verifies the suspend below min bitrate constraint is
3167// recognized and passed to the CreateMediaController call.
3168TEST_F(PeerConnectionMediaConfigTest,
3169 TestSuspendBelowMinBitrateConstraintTrue) {
3170 PeerConnectionInterface::RTCConfiguration config;
3171 FakeConstraints constraints;
3172
3173 constraints.AddOptional(
3174 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3175 true);
3176 const cricket::MediaConfig media_config =
3177 TestCreatePeerConnection(config, &constraints);
3178
3179 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003180}
3181
deadbeefab9b2d12015-10-14 11:33:11 -07003182// The following tests verify that session options are created correctly.
deadbeefc80741f2015-10-22 13:14:45 -07003183// TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
3184// "verify options are converted correctly", should be "pass options into
3185// CreateOffer and verify the correct offer is produced."
deadbeefab9b2d12015-10-14 11:33:11 -07003186
3187TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
3188 RTCOfferAnswerOptions rtc_options;
3189 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3190
3191 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003192 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003193
3194 rtc_options.offer_to_receive_audio =
3195 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003196 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003197}
3198
3199TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
3200 RTCOfferAnswerOptions rtc_options;
3201 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3202
3203 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003204 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003205
3206 rtc_options.offer_to_receive_video =
3207 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003208 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003209}
3210
3211// Test that a MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003212// OfferToReceiveAudio and OfferToReceiveVideo options are set.
deadbeefab9b2d12015-10-14 11:33:11 -07003213TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
3214 RTCOfferAnswerOptions rtc_options;
3215 rtc_options.offer_to_receive_audio = 1;
3216 rtc_options.offer_to_receive_video = 1;
3217
3218 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003219 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003220 EXPECT_TRUE(options.has_audio());
3221 EXPECT_TRUE(options.has_video());
3222 EXPECT_TRUE(options.bundle_enabled);
3223}
3224
3225// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003226// OfferToReceiveAudio is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003227TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
3228 RTCOfferAnswerOptions rtc_options;
3229 rtc_options.offer_to_receive_audio = 1;
3230
3231 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003232 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003233 EXPECT_TRUE(options.has_audio());
3234 EXPECT_FALSE(options.has_video());
3235 EXPECT_TRUE(options.bundle_enabled);
3236}
3237
3238// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003239// the default OfferOptions are used.
deadbeefab9b2d12015-10-14 11:33:11 -07003240TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
3241 RTCOfferAnswerOptions rtc_options;
3242
3243 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003244 options.transport_options["audio"] = cricket::TransportOptions();
3245 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003246 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefc80741f2015-10-22 13:14:45 -07003247 EXPECT_TRUE(options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07003248 EXPECT_FALSE(options.has_video());
deadbeefc80741f2015-10-22 13:14:45 -07003249 EXPECT_TRUE(options.bundle_enabled);
deadbeefab9b2d12015-10-14 11:33:11 -07003250 EXPECT_TRUE(options.vad_enabled);
deadbeef0ed85b22016-02-23 17:24:52 -08003251 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3252 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003253}
3254
3255// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003256// OfferToReceiveVideo is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003257TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
3258 RTCOfferAnswerOptions rtc_options;
3259 rtc_options.offer_to_receive_audio = 0;
3260 rtc_options.offer_to_receive_video = 1;
3261
3262 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003263 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003264 EXPECT_FALSE(options.has_audio());
3265 EXPECT_TRUE(options.has_video());
3266 EXPECT_TRUE(options.bundle_enabled);
3267}
3268
3269// Test that a correct MediaSessionOptions is created for an offer if
3270// UseRtpMux is set to false.
3271TEST(CreateSessionOptionsTest,
3272 GetMediaSessionOptionsForOfferWithBundleDisabled) {
3273 RTCOfferAnswerOptions rtc_options;
3274 rtc_options.offer_to_receive_audio = 1;
3275 rtc_options.offer_to_receive_video = 1;
3276 rtc_options.use_rtp_mux = false;
3277
3278 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003279 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003280 EXPECT_TRUE(options.has_audio());
3281 EXPECT_TRUE(options.has_video());
3282 EXPECT_FALSE(options.bundle_enabled);
3283}
3284
3285// Test that a correct MediaSessionOptions is created to restart ice if
3286// IceRestart is set. It also tests that subsequent MediaSessionOptions don't
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003287// have |audio_transport_options.ice_restart| etc. set.
deadbeefab9b2d12015-10-14 11:33:11 -07003288TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
3289 RTCOfferAnswerOptions rtc_options;
3290 rtc_options.ice_restart = true;
3291
3292 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003293 options.transport_options["audio"] = cricket::TransportOptions();
3294 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003295 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003296 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
3297 EXPECT_TRUE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003298
3299 rtc_options = RTCOfferAnswerOptions();
htaaac2dea2016-03-10 13:35:55 -08003300 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003301 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3302 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003303}
3304
3305// Test that the MediaConstraints in an answer don't affect if audio and video
3306// is offered in an offer but that if kOfferToReceiveAudio or
3307// kOfferToReceiveVideo constraints are true in an offer, the media type will be
3308// included in subsequent answers.
3309TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
3310 FakeConstraints answer_c;
3311 answer_c.SetMandatoryReceiveAudio(true);
3312 answer_c.SetMandatoryReceiveVideo(true);
3313
3314 cricket::MediaSessionOptions answer_options;
3315 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
3316 EXPECT_TRUE(answer_options.has_audio());
3317 EXPECT_TRUE(answer_options.has_video());
3318
deadbeefc80741f2015-10-22 13:14:45 -07003319 RTCOfferAnswerOptions rtc_offer_options;
deadbeefab9b2d12015-10-14 11:33:11 -07003320
3321 cricket::MediaSessionOptions offer_options;
htaaac2dea2016-03-10 13:35:55 -08003322 EXPECT_TRUE(
3323 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
deadbeefc80741f2015-10-22 13:14:45 -07003324 EXPECT_TRUE(offer_options.has_audio());
htaaac2dea2016-03-10 13:35:55 -08003325 EXPECT_TRUE(offer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003326
deadbeefc80741f2015-10-22 13:14:45 -07003327 RTCOfferAnswerOptions updated_rtc_offer_options;
3328 updated_rtc_offer_options.offer_to_receive_audio = 1;
3329 updated_rtc_offer_options.offer_to_receive_video = 1;
deadbeefab9b2d12015-10-14 11:33:11 -07003330
3331 cricket::MediaSessionOptions updated_offer_options;
htaaac2dea2016-03-10 13:35:55 -08003332 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
htaa2a49d92016-03-04 02:51:39 -08003333 &updated_offer_options));
deadbeefab9b2d12015-10-14 11:33:11 -07003334 EXPECT_TRUE(updated_offer_options.has_audio());
3335 EXPECT_TRUE(updated_offer_options.has_video());
3336
3337 // Since an offer has been created with both audio and video, subsequent
3338 // offers and answers should contain both audio and video.
3339 // Answers will only contain the media types that exist in the offer
3340 // regardless of the value of |updated_answer_options.has_audio| and
3341 // |updated_answer_options.has_video|.
3342 FakeConstraints updated_answer_c;
3343 answer_c.SetMandatoryReceiveAudio(false);
3344 answer_c.SetMandatoryReceiveVideo(false);
3345
3346 cricket::MediaSessionOptions updated_answer_options;
3347 EXPECT_TRUE(
3348 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
3349 EXPECT_TRUE(updated_answer_options.has_audio());
3350 EXPECT_TRUE(updated_answer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003351}
deadbeef3edec7c2016-12-10 11:44:26 -08003352
deadbeef293e9262017-01-11 12:28:30 -08003353TEST(RTCErrorTypeTest, OstreamOperator) {
deadbeef3edec7c2016-12-10 11:44:26 -08003354 std::ostringstream oss;
deadbeef293e9262017-01-11 12:28:30 -08003355 oss << webrtc::RTCErrorType::NONE << ' '
3356 << webrtc::RTCErrorType::INVALID_PARAMETER << ' '
3357 << webrtc::RTCErrorType::INTERNAL_ERROR;
deadbeef3edec7c2016-12-10 11:44:26 -08003358 EXPECT_EQ("NONE INVALID_PARAMETER INTERNAL_ERROR", oss.str());
3359}
deadbeef293e9262017-01-11 12:28:30 -08003360
3361// Tests a few random fields being different.
3362TEST(RTCConfigurationTest, ComparisonOperators) {
3363 PeerConnectionInterface::RTCConfiguration a;
3364 PeerConnectionInterface::RTCConfiguration b;
3365 EXPECT_EQ(a, b);
3366
3367 PeerConnectionInterface::RTCConfiguration c;
3368 c.servers.push_back(PeerConnectionInterface::IceServer());
3369 EXPECT_NE(a, c);
3370
3371 PeerConnectionInterface::RTCConfiguration d;
3372 d.type = PeerConnectionInterface::kRelay;
3373 EXPECT_NE(a, d);
3374
3375 PeerConnectionInterface::RTCConfiguration e;
3376 e.audio_jitter_buffer_max_packets = 5;
3377 EXPECT_NE(a, e);
3378
3379 PeerConnectionInterface::RTCConfiguration f;
3380 f.ice_connection_receiving_timeout = 1337;
3381 EXPECT_NE(a, f);
3382
3383 PeerConnectionInterface::RTCConfiguration g;
3384 g.disable_ipv6 = true;
3385 EXPECT_NE(a, g);
3386
3387 PeerConnectionInterface::RTCConfiguration h(
3388 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3389 EXPECT_NE(a, h);
3390}