blob: 09395a4b89a9335ca0e418e7cf5f876f65e320bd [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"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070029#include "webrtc/p2p/base/fakeportallocator.h"
zhihuang29ff8442016-07-27 11:07:25 -070030#include "webrtc/p2p/base/faketransportcontroller.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
deadbeeff33491e2017-01-20 17:01:45 -0800321#define MAYBE_SKIP_TEST(feature) \
322 if (!(feature())) { \
323 LOG(LS_INFO) << "Feature disabled... skipping"; \
324 return; \
325 }
326
perkjd61bf802016-03-24 03:16:19 -0700327using ::testing::Exactly;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700328using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700330using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331using webrtc::AudioTrackInterface;
332using webrtc::DataBuffer;
333using webrtc::DataChannelInterface;
334using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335using webrtc::IceCandidateInterface;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700336using webrtc::JsepSessionDescription;
deadbeefc80741f2015-10-22 13:14:45 -0700337using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700338using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339using webrtc::MediaStreamInterface;
340using webrtc::MediaStreamTrackInterface;
341using webrtc::MockCreateSessionDescriptionObserver;
342using webrtc::MockDataChannelObserver;
343using webrtc::MockSetSessionDescriptionObserver;
344using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700345using webrtc::NotifierInterface;
346using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347using webrtc::PeerConnectionInterface;
348using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800349using webrtc::RTCError;
350using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700351using webrtc::RtpReceiverInterface;
352using webrtc::RtpSenderInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353using webrtc::SdpParseError;
354using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700355using webrtc::StreamCollection;
356using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100357using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700358using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359using webrtc::VideoTrackInterface;
360
deadbeefab9b2d12015-10-14 11:33:11 -0700361typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
362
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363namespace {
364
365// Gets the first ssrc of given content type from the ContentInfo.
366bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
367 if (!content_info || !ssrc) {
368 return false;
369 }
370 const cricket::MediaContentDescription* media_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000371 static_cast<const cricket::MediaContentDescription*>(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 content_info->description);
373 if (!media_desc || media_desc->streams().empty()) {
374 return false;
375 }
376 *ssrc = media_desc->streams().begin()->first_ssrc();
377 return true;
378}
379
deadbeefd1a38b52016-12-10 13:15:33 -0800380// Get the ufrags out of an SDP blob. Useful for testing ICE restart
381// behavior.
382std::vector<std::string> GetUfrags(
383 const webrtc::SessionDescriptionInterface* desc) {
384 std::vector<std::string> ufrags;
385 for (const cricket::TransportInfo& info :
386 desc->description()->transport_infos()) {
387 ufrags.push_back(info.description.ice_ufrag);
388 }
389 return ufrags;
390}
391
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392void SetSsrcToZero(std::string* sdp) {
393 const char kSdpSsrcAtribute[] = "a=ssrc:";
394 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
395 size_t ssrc_pos = 0;
396 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
397 std::string::npos) {
398 size_t end_ssrc = sdp->find(" ", ssrc_pos);
399 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
400 ssrc_pos = end_ssrc;
401 }
402}
403
deadbeefab9b2d12015-10-14 11:33:11 -0700404// Check if |streams| contains the specified track.
405bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
406 const std::string& stream_label,
407 const std::string& track_id) {
408 for (const cricket::StreamParams& params : streams) {
409 if (params.sync_label == stream_label && params.id == track_id) {
410 return true;
411 }
412 }
413 return false;
414}
415
416// Check if |senders| contains the specified sender, by id.
417bool ContainsSender(
418 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
419 const std::string& id) {
420 for (const auto& sender : senders) {
421 if (sender->id() == id) {
422 return true;
423 }
424 }
425 return false;
426}
427
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700428// Check if |senders| contains the specified sender, by id and stream id.
429bool ContainsSender(
430 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
431 const std::string& id,
432 const std::string& stream_id) {
433 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700434 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700435 return true;
436 }
437 }
438 return false;
439}
440
deadbeefab9b2d12015-10-14 11:33:11 -0700441// Create a collection of streams.
442// CreateStreamCollection(1) creates a collection that
443// correspond to kSdpStringWithStream1.
444// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
445rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700446 int number_of_streams,
447 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700448 rtc::scoped_refptr<StreamCollection> local_collection(
449 StreamCollection::Create());
450
451 for (int i = 0; i < number_of_streams; ++i) {
452 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
453 webrtc::MediaStream::Create(kStreams[i]));
454
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700455 for (int j = 0; j < tracks_per_stream; ++j) {
456 // Add a local audio track.
457 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
458 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
459 nullptr));
460 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700461
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700462 // Add a local video track.
463 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
464 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
465 webrtc::FakeVideoTrackSource::Create()));
466 stream->AddTrack(video_track);
467 }
deadbeefab9b2d12015-10-14 11:33:11 -0700468
469 local_collection->AddStream(stream);
470 }
471 return local_collection;
472}
473
474// Check equality of StreamCollections.
475bool CompareStreamCollections(StreamCollectionInterface* s1,
476 StreamCollectionInterface* s2) {
477 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
478 return false;
479 }
480
481 for (size_t i = 0; i != s1->count(); ++i) {
482 if (s1->at(i)->label() != s2->at(i)->label()) {
483 return false;
484 }
485 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
486 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
487 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
488 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
489
490 if (audio_tracks1.size() != audio_tracks2.size()) {
491 return false;
492 }
493 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
494 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
495 return false;
496 }
497 }
498 if (video_tracks1.size() != video_tracks2.size()) {
499 return false;
500 }
501 for (size_t j = 0; j != video_tracks1.size(); ++j) {
502 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
503 return false;
504 }
505 }
506 }
507 return true;
508}
509
perkjd61bf802016-03-24 03:16:19 -0700510// Helper class to test Observer.
511class MockTrackObserver : public ObserverInterface {
512 public:
513 explicit MockTrackObserver(NotifierInterface* notifier)
514 : notifier_(notifier) {
515 notifier_->RegisterObserver(this);
516 }
517
518 ~MockTrackObserver() { Unregister(); }
519
520 void Unregister() {
521 if (notifier_) {
522 notifier_->UnregisterObserver(this);
523 notifier_ = nullptr;
524 }
525 }
526
527 MOCK_METHOD0(OnChanged, void());
528
529 private:
530 NotifierInterface* notifier_;
531};
532
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533class MockPeerConnectionObserver : public PeerConnectionObserver {
534 public:
kjellander71a1b612016-11-07 01:18:08 -0800535 // We need these using declarations because there are two versions of each of
536 // the below methods and we only override one of them.
537 // TODO(deadbeef): Remove once there's only one version of the methods.
538 using PeerConnectionObserver::OnAddStream;
539 using PeerConnectionObserver::OnRemoveStream;
540 using PeerConnectionObserver::OnDataChannel;
541
deadbeefab9b2d12015-10-14 11:33:11 -0700542 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200543 virtual ~MockPeerConnectionObserver() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 }
545 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
546 pc_ = pc;
547 if (pc) {
548 state_ = pc_->signaling_state();
549 }
550 }
nisseef8b61e2016-04-29 06:09:15 -0700551 void OnSignalingChange(
552 PeerConnectionInterface::SignalingState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 EXPECT_EQ(pc_->signaling_state(), new_state);
554 state_ = new_state;
555 }
556 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
557 virtual void OnStateChange(StateType state_changed) {
558 if (pc_.get() == NULL)
559 return;
560 switch (state_changed) {
561 case kSignalingState:
562 // OnSignalingChange and OnStateChange(kSignalingState) should always
563 // be called approximately simultaneously. To ease testing, we require
564 // that they always be called in that order. This check verifies
565 // that OnSignalingChange has just been called.
566 EXPECT_EQ(pc_->signaling_state(), state_);
567 break;
568 case kIceState:
569 ADD_FAILURE();
570 break;
571 default:
572 ADD_FAILURE();
573 break;
574 }
575 }
deadbeefab9b2d12015-10-14 11:33:11 -0700576
577 MediaStreamInterface* RemoteStream(const std::string& label) {
578 return remote_streams_->find(label);
579 }
580 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700581 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 last_added_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700583 remote_streams_->AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700585 void OnRemoveStream(
586 rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 last_removed_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700588 remote_streams_->RemoveStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 }
perkjdfb769d2016-02-09 03:09:43 -0800590 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700591 void OnDataChannel(
592 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 last_datachannel_ = data_channel;
594 }
595
perkjdfb769d2016-02-09 03:09:43 -0800596 void OnIceConnectionChange(
597 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 EXPECT_EQ(pc_->ice_connection_state(), new_state);
zhihuang81c3a032016-11-17 12:06:24 -0800599 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 }
perkjdfb769d2016-02-09 03:09:43 -0800601 void OnIceGatheringChange(
602 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
perkjdfb769d2016-02-09 03:09:43 -0800604 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete;
zhihuang81c3a032016-11-17 12:06:24 -0800605 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 }
perkjdfb769d2016-02-09 03:09:43 -0800607 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
609 pc_->ice_gathering_state());
610
611 std::string sdp;
612 EXPECT_TRUE(candidate->ToString(&sdp));
613 EXPECT_LT(0u, sdp.size());
614 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
615 candidate->sdp_mline_index(), sdp, NULL));
616 EXPECT_TRUE(last_candidate_.get() != NULL);
zhihuang81c3a032016-11-17 12:06:24 -0800617 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700618 }
619
620 void OnIceCandidatesRemoved(
621 const std::vector<cricket::Candidate>& candidates) override {
zhihuang81c3a032016-11-17 12:06:24 -0800622 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700623 }
624
625 void OnIceConnectionReceivingChange(bool receiving) override {
zhihuang81c3a032016-11-17 12:06:24 -0800626 callback_triggered_ = true;
627 }
628
zhihuangc63b8942016-12-02 15:41:10 -0800629 void OnAddTrack(
630 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
631 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
632 streams) override {
zhihuang81c3a032016-11-17 12:06:24 -0800633 EXPECT_TRUE(receiver != nullptr);
634 num_added_tracks_++;
635 last_added_track_label_ = receiver->id();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637
638 // Returns the label of the last added stream.
639 // Empty string if no stream have been added.
640 std::string GetLastAddedStreamLabel() {
641 if (last_added_stream_.get())
642 return last_added_stream_->label();
643 return "";
644 }
645 std::string GetLastRemovedStreamLabel() {
646 if (last_removed_stream_.get())
647 return last_removed_stream_->label();
648 return "";
649 }
650
zhihuang9763d562016-08-05 11:14:50 -0700651 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 PeerConnectionInterface::SignalingState state_;
kwibergd1fe2812016-04-27 06:47:29 -0700653 std::unique_ptr<IceCandidateInterface> last_candidate_;
zhihuang9763d562016-08-05 11:14:50 -0700654 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
deadbeefab9b2d12015-10-14 11:33:11 -0700655 rtc::scoped_refptr<StreamCollection> remote_streams_;
656 bool renegotiation_needed_ = false;
657 bool ice_complete_ = false;
zhihuang81c3a032016-11-17 12:06:24 -0800658 bool callback_triggered_ = false;
659 int num_added_tracks_ = 0;
660 std::string last_added_track_label_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661
662 private:
zhihuang9763d562016-08-05 11:14:50 -0700663 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
664 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665};
666
667} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700668
zhihuang29ff8442016-07-27 11:07:25 -0700669// The PeerConnectionMediaConfig tests below verify that configuration
670// and constraints are propagated into the MediaConfig passed to
671// CreateMediaController. These settings are intended for MediaChannel
672// constructors, but that is not exercised by these unittest.
673class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
674 public:
675 webrtc::MediaControllerInterface* CreateMediaController(
skvlad11a9cbf2016-10-07 11:53:05 -0700676 const cricket::MediaConfig& config,
677 webrtc::RtcEventLog* event_log) const override {
zhihuang29ff8442016-07-27 11:07:25 -0700678 create_media_controller_called_ = true;
679 create_media_controller_config_ = config;
680
681 webrtc::MediaControllerInterface* mc =
skvlad11a9cbf2016-10-07 11:53:05 -0700682 PeerConnectionFactory::CreateMediaController(config, event_log);
zhihuang29ff8442016-07-27 11:07:25 -0700683 EXPECT_TRUE(mc != nullptr);
684 return mc;
685 }
686
687 cricket::TransportController* CreateTransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700688 cricket::PortAllocator* port_allocator,
689 bool redetermine_role_on_ice_restart) override {
zhihuang29ff8442016-07-27 11:07:25 -0700690 transport_controller = new cricket::TransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700691 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
692 redetermine_role_on_ice_restart);
zhihuang29ff8442016-07-27 11:07:25 -0700693 return transport_controller;
694 }
695
696 cricket::TransportController* transport_controller;
697 // Mutable, so they can be modified in the above const-declared method.
698 mutable bool create_media_controller_called_ = false;
699 mutable cricket::MediaConfig create_media_controller_config_;
700};
701
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702class PeerConnectionInterfaceTest : public testing::Test {
703 protected:
phoglund37ebcf02016-01-08 05:04:57 -0800704 PeerConnectionInterfaceTest() {
705#ifdef WEBRTC_ANDROID
706 webrtc::InitializeAndroidObjects();
707#endif
708 }
709
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 virtual void SetUp() {
711 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700712 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
713 nullptr, nullptr, nullptr);
714 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700715 pc_factory_for_test_ =
716 new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
717 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 }
719
720 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700721 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 }
723
deadbeef293e9262017-01-11 12:28:30 -0800724 // DTLS does not work in a loopback call, so is disabled for most of the
725 // tests in this file.
726 void CreatePeerConnectionWithoutDtls() {
727 FakeConstraints no_dtls_constraints;
728 no_dtls_constraints.AddMandatory(
729 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
730
731 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
732 &no_dtls_constraints);
733 }
734
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700736 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
737 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 }
739
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700740 void CreatePeerConnectionWithIceTransportsType(
741 PeerConnectionInterface::IceTransportsType type) {
742 PeerConnectionInterface::RTCConfiguration config;
743 config.type = type;
744 return CreatePeerConnection(config, nullptr);
745 }
746
747 void CreatePeerConnectionWithIceServer(const std::string& uri,
748 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800749 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700751 server.uri = uri;
752 server.password = password;
753 config.servers.push_back(server);
754 CreatePeerConnection(config, nullptr);
755 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700757 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
758 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700759 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800760 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
761 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000762
Henrik Boströmd79599d2016-06-01 13:58:50 +0200763 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000764 bool dtls;
765 if (FindConstraint(constraints,
766 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
767 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200768 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800769 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
770 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000771 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200772 pc_ = pc_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800773 config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200774 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 ASSERT_TRUE(pc_.get() != NULL);
776 observer_.SetPeerConnectionInterface(pc_.get());
777 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
778 }
779
deadbeef0a6c4ca2015-10-06 11:38:28 -0700780 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800781 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700782 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700783 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800784 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700785
zhihuang9763d562016-08-05 11:14:50 -0700786 rtc::scoped_refptr<PeerConnectionInterface> pc;
hbosd7973cc2016-05-27 06:08:53 -0700787 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
788 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800789 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700790 }
791
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700793 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
795 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
796 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799
deadbeef0a6c4ca2015-10-06 11:38:28 -0700800 CreatePeerConnectionExpectFail(kStunInvalidPort);
801 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
802 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700804 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800805 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
806 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800808 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800810 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800812 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 }
814
815 void ReleasePeerConnection() {
816 pc_ = NULL;
817 observer_.SetPeerConnectionInterface(NULL);
818 }
819
deadbeefab9b2d12015-10-14 11:33:11 -0700820 void AddVideoStream(const std::string& label) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700822 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700824 rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
zhihuang9763d562016-08-05 11:14:50 -0700826 rtc::scoped_refptr<VideoTrackInterface> video_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 pc_factory_->CreateVideoTrack(label + "v0", video_source));
828 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000829 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
831 observer_.renegotiation_needed_ = false;
832 }
833
834 void AddVoiceStream(const std::string& label) {
835 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700836 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700838 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 pc_factory_->CreateAudioTrack(label + "a0", NULL));
840 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000841 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
843 observer_.renegotiation_needed_ = false;
844 }
845
846 void AddAudioVideoStream(const std::string& stream_label,
847 const std::string& audio_track_label,
848 const std::string& video_track_label) {
849 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700850 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 pc_factory_->CreateLocalMediaStream(stream_label));
zhihuang9763d562016-08-05 11:14:50 -0700852 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 pc_factory_->CreateAudioTrack(
854 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
855 stream->AddTrack(audio_track.get());
zhihuang9763d562016-08-05 11:14:50 -0700856 rtc::scoped_refptr<VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -0700857 pc_factory_->CreateVideoTrack(
858 video_track_label,
859 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000861 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
863 observer_.renegotiation_needed_ = false;
864 }
865
kwibergd1fe2812016-04-27 06:47:29 -0700866 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700867 bool offer,
868 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000869 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
870 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 MockCreateSessionDescriptionObserver>());
872 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700873 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700875 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
kwiberg2bbff992016-03-16 11:03:04 -0700878 desc->reset(observer->release_desc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 return observer->result();
880 }
881
kwibergd1fe2812016-04-27 06:47:29 -0700882 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700883 MediaConstraintsInterface* constraints) {
884 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 }
886
kwibergd1fe2812016-04-27 06:47:29 -0700887 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700888 MediaConstraintsInterface* constraints) {
889 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891
892 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000893 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
894 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 MockSetSessionDescriptionObserver>());
896 if (local) {
897 pc_->SetLocalDescription(observer, desc);
898 } else {
899 pc_->SetRemoteDescription(observer, desc);
900 }
zhihuang29ff8442016-07-27 11:07:25 -0700901 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
902 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 return observer->result();
905 }
906
907 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
908 return DoSetSessionDescription(desc, true);
909 }
910
911 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
912 return DoSetSessionDescription(desc, false);
913 }
914
915 // Calls PeerConnection::GetStats and check the return value.
916 // It does not verify the values in the StatReports since a RTCP packet might
917 // be required.
918 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000919 rtc::scoped_refptr<MockStatsObserver> observer(
920 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000921 if (!pc_->GetStats(
922 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 return false;
924 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
925 return observer->called();
926 }
927
928 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800929 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 // Create a local stream with audio&video tracks.
931 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
932 CreateOfferReceiveAnswer();
933 }
934
935 // Verify that RTP Header extensions has been negotiated for audio and video.
936 void VerifyRemoteRtpHeaderExtensions() {
937 const cricket::MediaContentDescription* desc =
938 cricket::GetFirstAudioContentDescription(
939 pc_->remote_description()->description());
940 ASSERT_TRUE(desc != NULL);
941 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
942
943 desc = cricket::GetFirstVideoContentDescription(
944 pc_->remote_description()->description());
945 ASSERT_TRUE(desc != NULL);
946 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
947 }
948
949 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700950 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700951 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 std::string sdp;
953 EXPECT_TRUE(offer->ToString(&sdp));
954 SessionDescriptionInterface* remote_offer =
955 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
956 sdp, NULL);
957 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
958 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
959 }
960
deadbeefab9b2d12015-10-14 11:33:11 -0700961 void CreateAndSetRemoteOffer(const std::string& sdp) {
962 SessionDescriptionInterface* remote_offer =
963 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
964 sdp, nullptr);
965 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
966 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
967 }
968
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700970 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700971 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972
973 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
974 // audio codec change, even if the parameter has nothing to do with
975 // receiving. Not all parameters are serialized to SDP.
976 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
977 // the SessionDescription, it is necessary to do that here to in order to
978 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
979 // https://code.google.com/p/webrtc/issues/detail?id=1356
980 std::string sdp;
981 EXPECT_TRUE(answer->ToString(&sdp));
982 SessionDescriptionInterface* new_answer =
983 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
984 sdp, NULL);
985 EXPECT_TRUE(DoSetLocalDescription(new_answer));
986 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
987 }
988
989 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700990 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700991 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
993 std::string sdp;
994 EXPECT_TRUE(answer->ToString(&sdp));
995 SessionDescriptionInterface* pr_answer =
996 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
997 sdp, NULL);
998 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
999 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1000 }
1001
1002 void CreateOfferReceiveAnswer() {
1003 CreateOfferAsLocalDescription();
1004 std::string sdp;
1005 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1006 CreateAnswerAsRemoteDescription(sdp);
1007 }
1008
1009 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001010 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001011 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1013 // audio codec change, even if the parameter has nothing to do with
1014 // receiving. Not all parameters are serialized to SDP.
1015 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1016 // the SessionDescription, it is necessary to do that here to in order to
1017 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1018 // https://code.google.com/p/webrtc/issues/detail?id=1356
1019 std::string sdp;
1020 EXPECT_TRUE(offer->ToString(&sdp));
1021 SessionDescriptionInterface* new_offer =
1022 webrtc::CreateSessionDescription(
1023 SessionDescriptionInterface::kOffer,
1024 sdp, NULL);
1025
1026 EXPECT_TRUE(DoSetLocalDescription(new_offer));
1027 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001028 // Wait for the ice_complete message, so that SDP will have candidates.
1029 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 }
1031
deadbeefab9b2d12015-10-14 11:33:11 -07001032 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1034 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001035 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 EXPECT_TRUE(DoSetRemoteDescription(answer));
1037 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1038 }
1039
deadbeefab9b2d12015-10-14 11:33:11 -07001040 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 webrtc::JsepSessionDescription* pr_answer =
1042 new webrtc::JsepSessionDescription(
1043 SessionDescriptionInterface::kPrAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001044 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
1046 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
1047 webrtc::JsepSessionDescription* answer =
1048 new webrtc::JsepSessionDescription(
1049 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001050 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 EXPECT_TRUE(DoSetRemoteDescription(answer));
1052 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1053 }
1054
1055 // Help function used for waiting until a the last signaled remote stream has
1056 // the same label as |stream_label|. In a few of the tests in this file we
1057 // answer with the same session description as we offer and thus we can
1058 // check if OnAddStream have been called with the same stream as we offer to
1059 // send.
1060 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
1061 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
1062 }
1063
1064 // Creates an offer and applies it as a local session description.
1065 // Creates an answer with the same SDP an the offer but removes all lines
1066 // that start with a:ssrc"
1067 void CreateOfferReceiveAnswerWithoutSsrc() {
1068 CreateOfferAsLocalDescription();
1069 std::string sdp;
1070 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1071 SetSsrcToZero(&sdp);
1072 CreateAnswerAsRemoteDescription(sdp);
1073 }
1074
deadbeefab9b2d12015-10-14 11:33:11 -07001075 // This function creates a MediaStream with label kStreams[0] and
1076 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1077 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001078 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001079 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001080 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001081 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1082 size_t number_of_video_tracks) {
1083 EXPECT_LE(number_of_audio_tracks, 2u);
1084 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001085
1086 reference_collection_ = StreamCollection::Create();
1087 std::string sdp_ms1 = std::string(kSdpStringInit);
1088
1089 std::string mediastream_label = kStreams[0];
1090
1091 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1092 webrtc::MediaStream::Create(mediastream_label));
1093 reference_collection_->AddStream(stream);
1094
1095 if (number_of_audio_tracks > 0) {
1096 sdp_ms1 += std::string(kSdpStringAudio);
1097 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1098 AddAudioTrack(kAudioTracks[0], stream);
1099 }
1100 if (number_of_audio_tracks > 1) {
1101 sdp_ms1 += kSdpStringMs1Audio1;
1102 AddAudioTrack(kAudioTracks[1], stream);
1103 }
1104
1105 if (number_of_video_tracks > 0) {
1106 sdp_ms1 += std::string(kSdpStringVideo);
1107 sdp_ms1 += std::string(kSdpStringMs1Video0);
1108 AddVideoTrack(kVideoTracks[0], stream);
1109 }
1110 if (number_of_video_tracks > 1) {
1111 sdp_ms1 += kSdpStringMs1Video1;
1112 AddVideoTrack(kVideoTracks[1], stream);
1113 }
1114
kwibergd1fe2812016-04-27 06:47:29 -07001115 return std::unique_ptr<SessionDescriptionInterface>(
kwiberg2bbff992016-03-16 11:03:04 -07001116 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1117 sdp_ms1, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001118 }
1119
1120 void AddAudioTrack(const std::string& track_id,
1121 MediaStreamInterface* stream) {
1122 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1123 webrtc::AudioTrack::Create(track_id, nullptr));
1124 ASSERT_TRUE(stream->AddTrack(audio_track));
1125 }
1126
1127 void AddVideoTrack(const std::string& track_id,
1128 MediaStreamInterface* stream) {
1129 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001130 webrtc::VideoTrack::Create(track_id,
1131 webrtc::FakeVideoTrackSource::Create()));
deadbeefab9b2d12015-10-14 11:33:11 -07001132 ASSERT_TRUE(stream->AddTrack(video_track));
1133 }
1134
kwibergfd8be342016-05-14 19:44:11 -07001135 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
deadbeef293e9262017-01-11 12:28:30 -08001136 CreatePeerConnectionWithoutDtls();
zhihuang8f65cdf2016-05-06 18:40:30 -07001137 AddVoiceStream(kStreamLabel1);
kwibergfd8be342016-05-14 19:44:11 -07001138 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001139 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1140 return offer;
1141 }
1142
kwibergfd8be342016-05-14 19:44:11 -07001143 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001144 CreateAnswerWithOneAudioStream() {
kwibergfd8be342016-05-14 19:44:11 -07001145 std::unique_ptr<SessionDescriptionInterface> offer =
zhihuang8f65cdf2016-05-06 18:40:30 -07001146 CreateOfferWithOneAudioStream();
1147 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergfd8be342016-05-14 19:44:11 -07001148 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001149 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1150 return answer;
1151 }
1152
1153 const std::string& GetFirstAudioStreamCname(
1154 const SessionDescriptionInterface* desc) {
1155 const cricket::ContentInfo* audio_content =
1156 cricket::GetFirstAudioContent(desc->description());
1157 const cricket::AudioContentDescription* audio_desc =
1158 static_cast<const cricket::AudioContentDescription*>(
1159 audio_content->description);
1160 return audio_desc->streams()[0].cname;
1161 }
1162
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001163 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001164 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001165 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1166 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1167 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001169 rtc::scoped_refptr<StreamCollection> reference_collection_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170};
1171
zhihuang29ff8442016-07-27 11:07:25 -07001172// Test that no callbacks on the PeerConnectionObserver are called after the
1173// PeerConnection is closed.
1174TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) {
zhihuang9763d562016-08-05 11:14:50 -07001175 rtc::scoped_refptr<PeerConnectionInterface> pc(
zhihuang29ff8442016-07-27 11:07:25 -07001176 pc_factory_for_test_->CreatePeerConnection(
1177 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr,
1178 nullptr, &observer_));
1179 observer_.SetPeerConnectionInterface(pc.get());
1180 pc->Close();
1181
1182 // No callbacks is expected to be called.
zhihuang81c3a032016-11-17 12:06:24 -08001183 observer_.callback_triggered_ = false;
zhihuang29ff8442016-07-27 11:07:25 -07001184 std::vector<cricket::Candidate> candidates;
1185 pc_factory_for_test_->transport_controller->SignalGatheringState(
1186 cricket::IceGatheringState{});
1187 pc_factory_for_test_->transport_controller->SignalCandidatesGathered(
1188 "", candidates);
1189 pc_factory_for_test_->transport_controller->SignalConnectionState(
1190 cricket::IceConnectionState{});
1191 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved(
1192 candidates);
1193 pc_factory_for_test_->transport_controller->SignalReceiving(false);
zhihuang81c3a032016-11-17 12:06:24 -08001194 EXPECT_FALSE(observer_.callback_triggered_);
zhihuang29ff8442016-07-27 11:07:25 -07001195}
1196
zhihuang8f65cdf2016-05-06 18:40:30 -07001197// Generate different CNAMEs when PeerConnections are created.
1198// The CNAMEs are expected to be generated randomly. It is possible
1199// that the test fails, though the possibility is very low.
1200TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001201 std::unique_ptr<SessionDescriptionInterface> offer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001202 CreateOfferWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001203 std::unique_ptr<SessionDescriptionInterface> offer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001204 CreateOfferWithOneAudioStream();
1205 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1206 GetFirstAudioStreamCname(offer2.get()));
1207}
1208
1209TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001210 std::unique_ptr<SessionDescriptionInterface> answer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001211 CreateAnswerWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001212 std::unique_ptr<SessionDescriptionInterface> answer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001213 CreateAnswerWithOneAudioStream();
1214 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1215 GetFirstAudioStreamCname(answer2.get()));
1216}
1217
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218TEST_F(PeerConnectionInterfaceTest,
1219 CreatePeerConnectionWithDifferentConfigurations) {
1220 CreatePeerConnectionWithDifferentConfigurations();
1221}
1222
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001223TEST_F(PeerConnectionInterfaceTest,
1224 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1225 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1226 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1227 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1228 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1229 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1230 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1231 port_allocator_->candidate_filter());
1232 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1233 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1234}
1235
1236// Test that when a PeerConnection is created with a nonzero candidate pool
1237// size, the pooled PortAllocatorSession is created with all the attributes
1238// in the RTCConfiguration.
1239TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1240 PeerConnectionInterface::RTCConfiguration config;
1241 PeerConnectionInterface::IceServer server;
1242 server.uri = kStunAddressOnly;
1243 config.servers.push_back(server);
1244 config.type = PeerConnectionInterface::kRelay;
1245 config.disable_ipv6 = true;
1246 config.tcp_candidate_policy =
1247 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001248 config.candidate_network_policy =
1249 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001250 config.ice_candidate_pool_size = 1;
1251 CreatePeerConnection(config, nullptr);
1252
1253 const cricket::FakePortAllocatorSession* session =
1254 static_cast<const cricket::FakePortAllocatorSession*>(
1255 port_allocator_->GetPooledSession());
1256 ASSERT_NE(nullptr, session);
1257 EXPECT_EQ(1UL, session->stun_servers().size());
1258 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1259 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001260 EXPECT_LT(0U,
1261 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001262}
1263
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001264// Test that the PeerConnection initializes the port allocator passed into it,
1265// and on the correct thread.
1266TEST_F(PeerConnectionInterfaceTest,
1267 CreatePeerConnectionInitializesPortAllocator) {
1268 rtc::Thread network_thread;
1269 network_thread.Start();
1270 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1271 webrtc::CreatePeerConnectionFactory(
1272 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
1273 nullptr, nullptr, nullptr));
1274 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1275 new cricket::FakePortAllocator(&network_thread, nullptr));
1276 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1277 PeerConnectionInterface::RTCConfiguration config;
1278 rtc::scoped_refptr<PeerConnectionInterface> pc(
1279 pc_factory->CreatePeerConnection(
1280 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1281 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1282 // so all we have to do here is check that it's initialized.
1283 EXPECT_TRUE(raw_port_allocator->initialized());
1284}
1285
deadbeef46c73892016-11-16 19:42:04 -08001286// Check that GetConfiguration returns the configuration the PeerConnection was
1287// constructed with, before SetConfiguration is called.
1288TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1289 PeerConnectionInterface::RTCConfiguration config;
1290 config.type = PeerConnectionInterface::kRelay;
1291 CreatePeerConnection(config, nullptr);
1292
1293 PeerConnectionInterface::RTCConfiguration returned_config =
1294 pc_->GetConfiguration();
1295 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1296}
1297
1298// Check that GetConfiguration returns the last configuration passed into
1299// SetConfiguration.
1300TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1301 CreatePeerConnection();
1302
1303 PeerConnectionInterface::RTCConfiguration config;
1304 config.type = PeerConnectionInterface::kRelay;
1305 EXPECT_TRUE(pc_->SetConfiguration(config));
1306
1307 PeerConnectionInterface::RTCConfiguration returned_config =
1308 pc_->GetConfiguration();
1309 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1310}
1311
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312TEST_F(PeerConnectionInterfaceTest, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001313 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001314 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 AddVoiceStream(kStreamLabel2);
1316 ASSERT_EQ(2u, pc_->local_streams()->count());
1317
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001318 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001319 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
zhihuang9763d562016-08-05 11:14:50 -07001321 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1322 pc_factory_->CreateAudioTrack(kStreamLabel3,
1323 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001325 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001326 EXPECT_EQ(3u, pc_->local_streams()->count());
1327
1328 // Remove the third stream.
1329 pc_->RemoveStream(pc_->local_streams()->at(2));
1330 EXPECT_EQ(2u, pc_->local_streams()->count());
1331
1332 // Remove the second stream.
1333 pc_->RemoveStream(pc_->local_streams()->at(1));
1334 EXPECT_EQ(1u, pc_->local_streams()->count());
1335
1336 // Remove the first stream.
1337 pc_->RemoveStream(pc_->local_streams()->at(0));
1338 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339}
1340
deadbeefab9b2d12015-10-14 11:33:11 -07001341// Test that the created offer includes streams we added.
1342TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001343 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001344 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001345 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001346 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001347
1348 const cricket::ContentInfo* audio_content =
1349 cricket::GetFirstAudioContent(offer->description());
1350 const cricket::AudioContentDescription* audio_desc =
1351 static_cast<const cricket::AudioContentDescription*>(
1352 audio_content->description);
1353 EXPECT_TRUE(
1354 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1355
1356 const cricket::ContentInfo* video_content =
1357 cricket::GetFirstVideoContent(offer->description());
1358 const cricket::VideoContentDescription* video_desc =
1359 static_cast<const cricket::VideoContentDescription*>(
1360 video_content->description);
1361 EXPECT_TRUE(
1362 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1363
1364 // Add another stream and ensure the offer includes both the old and new
1365 // streams.
1366 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001367 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001368
1369 audio_content = cricket::GetFirstAudioContent(offer->description());
1370 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1371 audio_content->description);
1372 EXPECT_TRUE(
1373 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1374 EXPECT_TRUE(
1375 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1376
1377 video_content = cricket::GetFirstVideoContent(offer->description());
1378 video_desc = static_cast<const cricket::VideoContentDescription*>(
1379 video_content->description);
1380 EXPECT_TRUE(
1381 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1382 EXPECT_TRUE(
1383 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1384}
1385
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001387 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001388 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 ASSERT_EQ(1u, pc_->local_streams()->count());
1390 pc_->RemoveStream(pc_->local_streams()->at(0));
1391 EXPECT_EQ(0u, pc_->local_streams()->count());
1392}
1393
deadbeefe1f9d832016-01-14 15:35:42 -08001394// Test for AddTrack and RemoveTrack methods.
1395// Tests that the created offer includes tracks we added,
1396// and that the RtpSenders are created correctly.
1397// Also tests that RemoveTrack removes the tracks from subsequent offers.
1398TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001399 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001400 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001401 rtc::scoped_refptr<MediaStreamInterface> stream(
deadbeefe1f9d832016-01-14 15:35:42 -08001402 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1403 std::vector<MediaStreamInterface*> stream_list;
1404 stream_list.push_back(stream.get());
zhihuang9763d562016-08-05 11:14:50 -07001405 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001406 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001407 rtc::scoped_refptr<VideoTrackInterface> video_track(
1408 pc_factory_->CreateVideoTrack(
1409 "video_track",
1410 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefe1f9d832016-01-14 15:35:42 -08001411 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1412 auto video_sender = pc_->AddTrack(video_track, stream_list);
deadbeefa601f5c2016-06-06 14:27:39 -07001413 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1414 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001415 EXPECT_EQ("audio_track", audio_sender->id());
1416 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001417 EXPECT_EQ(1UL, video_sender->stream_ids().size());
1418 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001419 EXPECT_EQ("video_track", video_sender->id());
1420 EXPECT_EQ(video_track, video_sender->track());
1421
1422 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001423 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001424 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001425
1426 const cricket::ContentInfo* audio_content =
1427 cricket::GetFirstAudioContent(offer->description());
1428 const cricket::AudioContentDescription* audio_desc =
1429 static_cast<const cricket::AudioContentDescription*>(
1430 audio_content->description);
1431 EXPECT_TRUE(
1432 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1433
1434 const cricket::ContentInfo* video_content =
1435 cricket::GetFirstVideoContent(offer->description());
1436 const cricket::VideoContentDescription* video_desc =
1437 static_cast<const cricket::VideoContentDescription*>(
1438 video_content->description);
1439 EXPECT_TRUE(
1440 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1441
1442 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1443
1444 // Now try removing the tracks.
1445 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1446 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1447
1448 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001449 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001450
1451 audio_content = cricket::GetFirstAudioContent(offer->description());
1452 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1453 audio_content->description);
1454 EXPECT_FALSE(
1455 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1456
1457 video_content = cricket::GetFirstVideoContent(offer->description());
1458 video_desc = static_cast<const cricket::VideoContentDescription*>(
1459 video_content->description);
1460 EXPECT_FALSE(
1461 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1462
1463 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1464
1465 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1466 // should return false.
1467 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1468 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1469}
1470
1471// Test creating senders without a stream specified,
1472// expecting a random stream ID to be generated.
1473TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001474 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001475 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001476 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001477 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001478 rtc::scoped_refptr<VideoTrackInterface> video_track(
1479 pc_factory_->CreateVideoTrack(
1480 "video_track",
1481 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefe1f9d832016-01-14 15:35:42 -08001482 auto audio_sender =
1483 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1484 auto video_sender =
1485 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1486 EXPECT_EQ("audio_track", audio_sender->id());
1487 EXPECT_EQ(audio_track, audio_sender->track());
1488 EXPECT_EQ("video_track", video_sender->id());
1489 EXPECT_EQ(video_track, video_sender->track());
1490 // If the ID is truly a random GUID, it should be infinitely unlikely they
1491 // will be the same.
deadbeefa601f5c2016-06-06 14:27:39 -07001492 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
deadbeefe1f9d832016-01-14 15:35:42 -08001493}
1494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1496 InitiateCall();
1497 WaitAndVerifyOnAddStream(kStreamLabel1);
1498 VerifyRemoteRtpHeaderExtensions();
1499}
1500
1501TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001502 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001503 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 CreateOfferAsLocalDescription();
1505 std::string offer;
1506 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1507 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1508 WaitAndVerifyOnAddStream(kStreamLabel1);
1509}
1510
1511TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001512 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001513 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514
1515 CreateOfferAsRemoteDescription();
1516 CreateAnswerAsLocalDescription();
1517
1518 WaitAndVerifyOnAddStream(kStreamLabel1);
1519}
1520
1521TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001522 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001523 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524
1525 CreateOfferAsRemoteDescription();
1526 CreatePrAnswerAsLocalDescription();
1527 CreateAnswerAsLocalDescription();
1528
1529 WaitAndVerifyOnAddStream(kStreamLabel1);
1530}
1531
1532TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1533 InitiateCall();
1534 ASSERT_EQ(1u, pc_->remote_streams()->count());
1535 pc_->RemoveStream(pc_->local_streams()->at(0));
1536 CreateOfferReceiveAnswer();
1537 EXPECT_EQ(0u, pc_->remote_streams()->count());
deadbeefab9b2d12015-10-14 11:33:11 -07001538 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 CreateOfferReceiveAnswer();
1540}
1541
1542// Tests that after negotiating an audio only call, the respondent can perform a
1543// renegotiation that removes the audio stream.
1544TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001545 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 AddVoiceStream(kStreamLabel1);
1547 CreateOfferAsRemoteDescription();
1548 CreateAnswerAsLocalDescription();
1549
1550 ASSERT_EQ(1u, pc_->remote_streams()->count());
1551 pc_->RemoveStream(pc_->local_streams()->at(0));
1552 CreateOfferReceiveAnswer();
1553 EXPECT_EQ(0u, pc_->remote_streams()->count());
1554}
1555
1556// Test that candidates are generated and that we can parse our own candidates.
1557TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001558 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559
1560 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1561 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001562 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefab9b2d12015-10-14 11:33:11 -07001563 AddVideoStream(kStreamLabel1);
deadbeefc80741f2015-10-22 13:14:45 -07001564 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001565 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566
1567 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001568 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001569 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001570 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571
1572 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1573 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1574
1575 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1576}
1577
deadbeefab9b2d12015-10-14 11:33:11 -07001578// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579// not unique.
1580TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001581 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001583 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001584 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001585 EXPECT_TRUE(offer);
1586 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587
1588 // Create a local stream with audio&video tracks having same label.
1589 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1590
1591 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001592 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593
1594 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001595 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001596 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597}
1598
1599// Test that we will get different SSRCs for each tracks in the offer and answer
1600// we created.
1601TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001602 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 // Create a local stream with audio&video tracks having different labels.
1604 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1605
1606 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001607 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001608 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 int audio_ssrc = 0;
1610 int video_ssrc = 0;
1611 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1612 &audio_ssrc));
1613 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1614 &video_ssrc));
1615 EXPECT_NE(audio_ssrc, video_ssrc);
1616
1617 // Test CreateAnswer
1618 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergd1fe2812016-04-27 06:47:29 -07001619 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001620 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 audio_ssrc = 0;
1622 video_ssrc = 0;
1623 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1624 &audio_ssrc));
1625 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1626 &video_ssrc));
1627 EXPECT_NE(audio_ssrc, video_ssrc);
1628}
1629
deadbeefeb459812015-12-15 19:24:43 -08001630// Test that it's possible to call AddTrack on a MediaStream after adding
1631// the stream to a PeerConnection.
1632// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1633TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001634 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001635 // Create audio stream and add to PeerConnection.
1636 AddVoiceStream(kStreamLabel1);
1637 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1638
1639 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001640 rtc::scoped_refptr<VideoTrackInterface> video_track(
1641 pc_factory_->CreateVideoTrack(
1642 "video_label",
1643 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefeb459812015-12-15 19:24:43 -08001644 stream->AddTrack(video_track.get());
1645
kwibergd1fe2812016-04-27 06:47:29 -07001646 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001647 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001648
1649 const cricket::MediaContentDescription* video_desc =
1650 cricket::GetFirstVideoContentDescription(offer->description());
1651 EXPECT_TRUE(video_desc != nullptr);
1652}
1653
1654// Test that it's possible to call RemoveTrack on a MediaStream after adding
1655// the stream to a PeerConnection.
1656// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1657TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001658 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001659 // Create audio/video stream and add to PeerConnection.
1660 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1661 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1662
1663 // Remove the video track.
1664 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1665
kwibergd1fe2812016-04-27 06:47:29 -07001666 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001667 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001668
1669 const cricket::MediaContentDescription* video_desc =
1670 cricket::GetFirstVideoContentDescription(offer->description());
1671 EXPECT_TRUE(video_desc == nullptr);
1672}
1673
deadbeefbd7d8f72015-12-18 16:58:44 -08001674// Test creating a sender with a stream ID, and ensure the ID is populated
1675// in the offer.
1676TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001677 CreatePeerConnectionWithoutDtls();
deadbeefbd7d8f72015-12-18 16:58:44 -08001678 pc_->CreateSender("video", kStreamLabel1);
1679
kwibergd1fe2812016-04-27 06:47:29 -07001680 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001681 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001682
1683 const cricket::MediaContentDescription* video_desc =
1684 cricket::GetFirstVideoContentDescription(offer->description());
1685 ASSERT_TRUE(video_desc != nullptr);
1686 ASSERT_EQ(1u, video_desc->streams().size());
1687 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1688}
1689
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690// Test that we can specify a certain track that we want statistics about.
1691TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1692 InitiateCall();
1693 ASSERT_LT(0u, pc_->remote_streams()->count());
1694 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001695 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1697 EXPECT_TRUE(DoGetStats(remote_audio));
1698
1699 // Remove the stream. Since we are sending to our selves the local
1700 // and the remote stream is the same.
1701 pc_->RemoveStream(pc_->local_streams()->at(0));
1702 // Do a re-negotiation.
1703 CreateOfferReceiveAnswer();
1704
1705 ASSERT_EQ(0u, pc_->remote_streams()->count());
1706
1707 // Test that we still can get statistics for the old track. Even if it is not
1708 // sent any longer.
1709 EXPECT_TRUE(DoGetStats(remote_audio));
1710}
1711
1712// Test that we can get stats on a video track.
1713TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1714 InitiateCall();
1715 ASSERT_LT(0u, pc_->remote_streams()->count());
1716 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001717 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1719 EXPECT_TRUE(DoGetStats(remote_video));
1720}
1721
1722// Test that we don't get statistics for an invalid track.
zhihuange9e94c32016-11-04 11:38:15 -07001723TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001725 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 pc_factory_->CreateAudioTrack("unknown track", NULL));
1727 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1728}
1729
1730// This test setup two RTP data channels in loop back.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 FakeConstraints constraints;
1733 constraints.SetAllowRtpDataChannels();
1734 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001735 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001737 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 pc_->CreateDataChannel("test2", NULL);
1739 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001740 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001742 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 new MockDataChannelObserver(data2));
1744
1745 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1746 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1747 std::string data_to_send1 = "testing testing";
1748 std::string data_to_send2 = "testing something else";
1749 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1750
1751 CreateOfferReceiveAnswer();
1752 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1753 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1754
1755 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1756 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1757 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1758 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1759
1760 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1761 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1762
1763 data1->Close();
1764 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1765 CreateOfferReceiveAnswer();
1766 EXPECT_FALSE(observer1->IsOpen());
1767 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1768 EXPECT_TRUE(observer2->IsOpen());
1769
1770 data_to_send2 = "testing something else again";
1771 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1772
1773 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1774}
1775
1776// This test verifies that sendnig binary data over RTP data channels should
1777// fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 FakeConstraints constraints;
1780 constraints.SetAllowRtpDataChannels();
1781 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001782 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001784 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 pc_->CreateDataChannel("test2", NULL);
1786 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001787 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001789 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 new MockDataChannelObserver(data2));
1791
1792 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1793 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1794
1795 CreateOfferReceiveAnswer();
1796 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1797 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1798
1799 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1800 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1801
jbaucheec21bd2016-03-20 06:15:43 -07001802 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1804}
1805
1806// This test setup a RTP data channels in loop back and test that a channel is
1807// opened even if the remote end answer with a zero SSRC.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 FakeConstraints constraints;
1810 constraints.SetAllowRtpDataChannels();
1811 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001812 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001814 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 new MockDataChannelObserver(data1));
1816
1817 CreateOfferReceiveAnswerWithoutSsrc();
1818
1819 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1820
1821 data1->Close();
1822 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1823 CreateOfferReceiveAnswerWithoutSsrc();
1824 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1825 EXPECT_FALSE(observer1->IsOpen());
1826}
1827
1828// This test that if a data channel is added in an answer a receive only channel
1829// channel is created.
1830TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1831 FakeConstraints constraints;
1832 constraints.SetAllowRtpDataChannels();
1833 CreatePeerConnection(&constraints);
1834
1835 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07001836 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 pc_->CreateDataChannel(offer_label, NULL);
1838
1839 CreateOfferAsLocalDescription();
1840
1841 // Replace the data channel label in the offer and apply it as an answer.
1842 std::string receive_label = "answer_channel";
1843 std::string sdp;
1844 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001845 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 receive_label.c_str(), receive_label.length(),
1847 &sdp);
1848 CreateAnswerAsRemoteDescription(sdp);
1849
1850 // Verify that a new incoming data channel has been created and that
1851 // it is open but can't we written to.
1852 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1853 DataChannelInterface* received_channel = observer_.last_datachannel_;
1854 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1855 EXPECT_EQ(receive_label, received_channel->label());
1856 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1857
1858 // Verify that the channel we initially offered has been rejected.
1859 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1860
1861 // Do another offer / answer exchange and verify that the data channel is
1862 // opened.
1863 CreateOfferReceiveAnswer();
1864 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1865 kTimeout);
1866}
1867
1868// This test that no data channel is returned if a reliable channel is
1869// requested.
1870// TODO(perkj): Remove this test once reliable channels are implemented.
1871TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1872 FakeConstraints constraints;
1873 constraints.SetAllowRtpDataChannels();
1874 CreatePeerConnection(&constraints);
1875
1876 std::string label = "test";
1877 webrtc::DataChannelInit config;
1878 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07001879 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 pc_->CreateDataChannel(label, &config);
1881 EXPECT_TRUE(channel == NULL);
1882}
1883
deadbeefab9b2d12015-10-14 11:33:11 -07001884// Verifies that duplicated label is not allowed for RTP data channel.
1885TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1886 FakeConstraints constraints;
1887 constraints.SetAllowRtpDataChannels();
1888 CreatePeerConnection(&constraints);
1889
1890 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001891 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001892 pc_->CreateDataChannel(label, nullptr);
1893 EXPECT_NE(channel, nullptr);
1894
zhihuang9763d562016-08-05 11:14:50 -07001895 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001896 pc_->CreateDataChannel(label, nullptr);
1897 EXPECT_EQ(dup_channel, nullptr);
1898}
1899
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900// This tests that a SCTP data channel is returned using different
1901// DataChannelInit configurations.
1902TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1903 FakeConstraints constraints;
1904 constraints.SetAllowDtlsSctpDataChannels();
1905 CreatePeerConnection(&constraints);
1906
1907 webrtc::DataChannelInit config;
1908
zhihuang9763d562016-08-05 11:14:50 -07001909 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 pc_->CreateDataChannel("1", &config);
1911 EXPECT_TRUE(channel != NULL);
1912 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001913 EXPECT_TRUE(observer_.renegotiation_needed_);
1914 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915
1916 config.ordered = false;
1917 channel = pc_->CreateDataChannel("2", &config);
1918 EXPECT_TRUE(channel != NULL);
1919 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001920 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921
1922 config.ordered = true;
1923 config.maxRetransmits = 0;
1924 channel = pc_->CreateDataChannel("3", &config);
1925 EXPECT_TRUE(channel != NULL);
1926 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001927 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
1929 config.maxRetransmits = -1;
1930 config.maxRetransmitTime = 0;
1931 channel = pc_->CreateDataChannel("4", &config);
1932 EXPECT_TRUE(channel != NULL);
1933 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001934 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935}
1936
1937// This tests that no data channel is returned if both maxRetransmits and
1938// maxRetransmitTime are set for SCTP data channels.
1939TEST_F(PeerConnectionInterfaceTest,
1940 CreateSctpDataChannelShouldFailForInvalidConfig) {
1941 FakeConstraints constraints;
1942 constraints.SetAllowDtlsSctpDataChannels();
1943 CreatePeerConnection(&constraints);
1944
1945 std::string label = "test";
1946 webrtc::DataChannelInit config;
1947 config.maxRetransmits = 0;
1948 config.maxRetransmitTime = 0;
1949
zhihuang9763d562016-08-05 11:14:50 -07001950 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 pc_->CreateDataChannel(label, &config);
1952 EXPECT_TRUE(channel == NULL);
1953}
1954
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955// The test verifies that creating a SCTP data channel with an id already in use
1956// or out of range should fail.
1957TEST_F(PeerConnectionInterfaceTest,
1958 CreateSctpDataChannelWithInvalidIdShouldFail) {
1959 FakeConstraints constraints;
1960 constraints.SetAllowDtlsSctpDataChannels();
1961 CreatePeerConnection(&constraints);
1962
1963 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07001964 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001966 config.id = 1;
1967 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 EXPECT_TRUE(channel != NULL);
1969 EXPECT_EQ(1, channel->id());
1970
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971 channel = pc_->CreateDataChannel("x", &config);
1972 EXPECT_TRUE(channel == NULL);
1973
1974 config.id = cricket::kMaxSctpSid;
1975 channel = pc_->CreateDataChannel("max", &config);
1976 EXPECT_TRUE(channel != NULL);
1977 EXPECT_EQ(config.id, channel->id());
1978
1979 config.id = cricket::kMaxSctpSid + 1;
1980 channel = pc_->CreateDataChannel("x", &config);
1981 EXPECT_TRUE(channel == NULL);
1982}
1983
deadbeefab9b2d12015-10-14 11:33:11 -07001984// Verifies that duplicated label is allowed for SCTP data channel.
1985TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
1986 FakeConstraints constraints;
1987 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1988 true);
1989 CreatePeerConnection(&constraints);
1990
1991 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001992 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001993 pc_->CreateDataChannel(label, nullptr);
1994 EXPECT_NE(channel, nullptr);
1995
zhihuang9763d562016-08-05 11:14:50 -07001996 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001997 pc_->CreateDataChannel(label, nullptr);
1998 EXPECT_NE(dup_channel, nullptr);
1999}
2000
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002001// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2002// DataChannel.
2003TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
2004 FakeConstraints constraints;
2005 constraints.SetAllowRtpDataChannels();
2006 CreatePeerConnection(&constraints);
2007
zhihuang9763d562016-08-05 11:14:50 -07002008 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002009 pc_->CreateDataChannel("test1", NULL);
2010 EXPECT_TRUE(observer_.renegotiation_needed_);
2011 observer_.renegotiation_needed_ = false;
2012
zhihuang9763d562016-08-05 11:14:50 -07002013 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002014 pc_->CreateDataChannel("test2", NULL);
2015 EXPECT_TRUE(observer_.renegotiation_needed_);
2016}
2017
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018// This test that a data channel closes when a PeerConnection is deleted/closed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 FakeConstraints constraints;
2021 constraints.SetAllowRtpDataChannels();
2022 CreatePeerConnection(&constraints);
2023
zhihuang9763d562016-08-05 11:14:50 -07002024 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002026 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 pc_->CreateDataChannel("test2", NULL);
2028 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002029 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002031 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032 new MockDataChannelObserver(data2));
2033
2034 CreateOfferReceiveAnswer();
2035 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2036 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2037
2038 ReleasePeerConnection();
2039 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2040 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2041}
2042
2043// This test that data channels can be rejected in an answer.
2044TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
2045 FakeConstraints constraints;
2046 constraints.SetAllowRtpDataChannels();
2047 CreatePeerConnection(&constraints);
2048
zhihuang9763d562016-08-05 11:14:50 -07002049 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 pc_->CreateDataChannel("offer_channel", NULL));
2051
2052 CreateOfferAsLocalDescription();
2053
2054 // Create an answer where the m-line for data channels are rejected.
2055 std::string sdp;
2056 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2057 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
2058 SessionDescriptionInterface::kAnswer);
2059 EXPECT_TRUE(answer->Initialize(sdp, NULL));
2060 cricket::ContentInfo* data_info =
2061 answer->description()->GetContentByName("data");
2062 data_info->rejected = true;
2063
2064 DoSetRemoteDescription(answer);
2065 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2066}
2067
2068// Test that we can create a session description from an SDP string from
2069// FireFox, use it as a remote session description, generate an answer and use
2070// the answer as a local description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002071TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
deadbeeff33491e2017-01-20 17:01:45 -08002072 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 FakeConstraints constraints;
2074 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2075 true);
2076 CreatePeerConnection(&constraints);
2077 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2078 SessionDescriptionInterface* desc =
2079 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002080 webrtc::kFireFoxSdpOffer, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2082 CreateAnswerAsLocalDescription();
2083 ASSERT_TRUE(pc_->local_description() != NULL);
2084 ASSERT_TRUE(pc_->remote_description() != NULL);
2085
2086 const cricket::ContentInfo* content =
2087 cricket::GetFirstAudioContent(pc_->local_description()->description());
2088 ASSERT_TRUE(content != NULL);
2089 EXPECT_FALSE(content->rejected);
2090
2091 content =
2092 cricket::GetFirstVideoContent(pc_->local_description()->description());
2093 ASSERT_TRUE(content != NULL);
2094 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002095#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 content =
2097 cricket::GetFirstDataContent(pc_->local_description()->description());
2098 ASSERT_TRUE(content != NULL);
2099 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002100#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101}
2102
deadbeef8662f942017-01-20 21:20:51 -08002103// Test that an offer can be received which offers DTLS with SDES fallback.
2104// Regression test for issue:
2105// https://bugs.chromium.org/p/webrtc/issues/detail?id=6972
2106TEST_F(PeerConnectionInterfaceTest, ReceiveDtlsSdesFallbackOffer) {
2107 FakeConstraints constraints;
2108 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2109 true);
2110 CreatePeerConnection(&constraints);
2111 // Wait for fake certificate to be generated. Previously, this is what caused
2112 // the "a=crypto" lines to be rejected.
2113 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2114 ASSERT_NE(nullptr, fake_certificate_generator_);
2115 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2116 kTimeout);
2117 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
2118 SessionDescriptionInterface::kOffer, kDtlsSdesFallbackSdp, nullptr);
2119 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2120 CreateAnswerAsLocalDescription();
2121}
2122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123// Test that we can create an audio only offer and receive an answer with a
2124// limited set of audio codecs and receive an updated offer with more audio
2125// codecs, where the added codecs are not supported.
2126TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002127 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 AddVoiceStream("audio_label");
2129 CreateOfferAsLocalDescription();
2130
2131 SessionDescriptionInterface* answer =
2132 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
jbauchfabe2c92015-07-16 13:43:14 -07002133 webrtc::kAudioSdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 EXPECT_TRUE(DoSetSessionDescription(answer, false));
2135
2136 SessionDescriptionInterface* updated_offer =
2137 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002138 webrtc::kAudioSdpWithUnsupportedCodecs,
2139 nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
2141 CreateAnswerAsLocalDescription();
2142}
2143
deadbeefc80741f2015-10-22 13:14:45 -07002144// Test that if we're receiving (but not sending) a track, subsequent offers
2145// will have m-lines with a=recvonly.
2146TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2147 FakeConstraints constraints;
2148 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2149 true);
2150 CreatePeerConnection(&constraints);
2151 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2152 CreateAnswerAsLocalDescription();
2153
2154 // At this point we should be receiving stream 1, but not sending anything.
2155 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002156 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002157 DoCreateOffer(&offer, nullptr);
2158
2159 const cricket::ContentInfo* video_content =
2160 cricket::GetFirstVideoContent(offer->description());
2161 const cricket::VideoContentDescription* video_desc =
2162 static_cast<const cricket::VideoContentDescription*>(
2163 video_content->description);
2164 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
2165
2166 const cricket::ContentInfo* audio_content =
2167 cricket::GetFirstAudioContent(offer->description());
2168 const cricket::AudioContentDescription* audio_desc =
2169 static_cast<const cricket::AudioContentDescription*>(
2170 audio_content->description);
2171 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
2172}
2173
2174// Test that if we're receiving (but not sending) a track, and the
2175// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2176// false, the generated m-lines will be a=inactive.
2177TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2178 FakeConstraints constraints;
2179 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2180 true);
2181 CreatePeerConnection(&constraints);
2182 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2183 CreateAnswerAsLocalDescription();
2184
2185 // At this point we should be receiving stream 1, but not sending anything.
2186 // A new offer would be recvonly, but we'll set the "no receive" constraints
2187 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002188 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002189 FakeConstraints offer_constraints;
2190 offer_constraints.AddMandatory(
2191 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2192 offer_constraints.AddMandatory(
2193 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2194 DoCreateOffer(&offer, &offer_constraints);
2195
2196 const cricket::ContentInfo* video_content =
2197 cricket::GetFirstVideoContent(offer->description());
2198 const cricket::VideoContentDescription* video_desc =
2199 static_cast<const cricket::VideoContentDescription*>(
2200 video_content->description);
2201 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
2202
2203 const cricket::ContentInfo* audio_content =
2204 cricket::GetFirstAudioContent(offer->description());
2205 const cricket::AudioContentDescription* audio_desc =
2206 static_cast<const cricket::AudioContentDescription*>(
2207 audio_content->description);
2208 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
2209}
2210
deadbeef653b8e02015-11-11 12:55:10 -08002211// Test that we can use SetConfiguration to change the ICE servers of the
2212// PortAllocator.
2213TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2214 CreatePeerConnection();
2215
2216 PeerConnectionInterface::RTCConfiguration config;
2217 PeerConnectionInterface::IceServer server;
2218 server.uri = "stun:test_hostname";
2219 config.servers.push_back(server);
2220 EXPECT_TRUE(pc_->SetConfiguration(config));
2221
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002222 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2223 EXPECT_EQ("test_hostname",
2224 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002225}
2226
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002227TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2228 CreatePeerConnection();
2229 PeerConnectionInterface::RTCConfiguration config;
2230 config.type = PeerConnectionInterface::kRelay;
2231 EXPECT_TRUE(pc_->SetConfiguration(config));
2232 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2233}
2234
deadbeef293e9262017-01-11 12:28:30 -08002235TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
2236 PeerConnectionInterface::RTCConfiguration config;
2237 config.prune_turn_ports = false;
2238 CreatePeerConnection(config, nullptr);
2239 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2240
2241 config.prune_turn_ports = true;
2242 EXPECT_TRUE(pc_->SetConfiguration(config));
2243 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2244}
2245
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002246// Test that when SetConfiguration changes both the pool size and other
2247// attributes, the pooled session is created with the updated attributes.
2248TEST_F(PeerConnectionInterfaceTest,
2249 SetConfigurationCreatesPooledSessionCorrectly) {
2250 CreatePeerConnection();
2251 PeerConnectionInterface::RTCConfiguration config;
2252 config.ice_candidate_pool_size = 1;
2253 PeerConnectionInterface::IceServer server;
2254 server.uri = kStunAddressOnly;
2255 config.servers.push_back(server);
2256 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002257 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002258
2259 const cricket::FakePortAllocatorSession* session =
2260 static_cast<const cricket::FakePortAllocatorSession*>(
2261 port_allocator_->GetPooledSession());
2262 ASSERT_NE(nullptr, session);
2263 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002264}
2265
deadbeef293e9262017-01-11 12:28:30 -08002266// Test that after SetLocalDescription, changing the pool size is not allowed,
2267// and an invalid modification error is returned.
deadbeef6de92f92016-12-12 18:49:32 -08002268TEST_F(PeerConnectionInterfaceTest,
2269 CantChangePoolSizeAfterSetLocalDescription) {
2270 CreatePeerConnection();
2271 // Start by setting a size of 1.
2272 PeerConnectionInterface::RTCConfiguration config;
2273 config.ice_candidate_pool_size = 1;
2274 EXPECT_TRUE(pc_->SetConfiguration(config));
2275
2276 // Set remote offer; can still change pool size at this point.
2277 CreateOfferAsRemoteDescription();
2278 config.ice_candidate_pool_size = 2;
2279 EXPECT_TRUE(pc_->SetConfiguration(config));
2280
2281 // Set local answer; now it's too late.
2282 CreateAnswerAsLocalDescription();
2283 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002284 RTCError error;
2285 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2286 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2287}
2288
2289// Test that SetConfiguration returns an invalid modification error if
2290// modifying a field in the configuration that isn't allowed to be modified.
2291TEST_F(PeerConnectionInterfaceTest,
2292 SetConfigurationReturnsInvalidModificationError) {
2293 PeerConnectionInterface::RTCConfiguration config;
2294 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2295 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2296 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2297 CreatePeerConnection(config, nullptr);
2298
2299 PeerConnectionInterface::RTCConfiguration modified_config = config;
2300 modified_config.bundle_policy =
2301 PeerConnectionInterface::kBundlePolicyMaxBundle;
2302 RTCError error;
2303 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2304 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2305
2306 modified_config = config;
2307 modified_config.rtcp_mux_policy =
2308 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2309 error.set_type(RTCErrorType::NONE);
2310 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2311 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2312
2313 modified_config = config;
2314 modified_config.continual_gathering_policy =
2315 PeerConnectionInterface::GATHER_CONTINUALLY;
2316 error.set_type(RTCErrorType::NONE);
2317 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2318 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2319}
2320
2321// Test that SetConfiguration returns a range error if the candidate pool size
2322// is negative or larger than allowed by the spec.
2323TEST_F(PeerConnectionInterfaceTest,
2324 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2325 PeerConnectionInterface::RTCConfiguration config;
2326 CreatePeerConnection(config, nullptr);
2327
2328 config.ice_candidate_pool_size = -1;
2329 RTCError error;
2330 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2331 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2332
2333 config.ice_candidate_pool_size = INT_MAX;
2334 error.set_type(RTCErrorType::NONE);
2335 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2336 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2337}
2338
2339// Test that SetConfiguration returns a syntax error if parsing an ICE server
2340// URL failed.
2341TEST_F(PeerConnectionInterfaceTest,
2342 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2343 PeerConnectionInterface::RTCConfiguration config;
2344 CreatePeerConnection(config, nullptr);
2345
2346 PeerConnectionInterface::IceServer bad_server;
2347 bad_server.uri = "stunn:www.example.com";
2348 config.servers.push_back(bad_server);
2349 RTCError error;
2350 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2351 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2352}
2353
2354// Test that SetConfiguration returns an invalid parameter error if a TURN
2355// IceServer is missing a username or password.
2356TEST_F(PeerConnectionInterfaceTest,
2357 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2358 PeerConnectionInterface::RTCConfiguration config;
2359 CreatePeerConnection(config, nullptr);
2360
2361 PeerConnectionInterface::IceServer bad_server;
2362 bad_server.uri = "turn:www.example.com";
2363 // Missing password.
2364 bad_server.username = "foo";
2365 config.servers.push_back(bad_server);
2366 RTCError error;
2367 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2368 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002369}
2370
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371// Test that PeerConnection::Close changes the states to closed and all remote
2372// tracks change state to ended.
2373TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2374 // Initialize a PeerConnection and negotiate local and remote session
2375 // description.
2376 InitiateCall();
2377 ASSERT_EQ(1u, pc_->local_streams()->count());
2378 ASSERT_EQ(1u, pc_->remote_streams()->count());
2379
2380 pc_->Close();
2381
2382 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2383 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2384 pc_->ice_connection_state());
2385 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2386 pc_->ice_gathering_state());
2387
2388 EXPECT_EQ(1u, pc_->local_streams()->count());
2389 EXPECT_EQ(1u, pc_->remote_streams()->count());
2390
zhihuang9763d562016-08-05 11:14:50 -07002391 rtc::scoped_refptr<MediaStreamInterface> remote_stream =
2392 pc_->remote_streams()->at(0);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002393 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002394 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002395 remote_stream->GetAudioTracks()[0]->state(), kTimeout);
2396 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2397 remote_stream->GetVideoTracks()[0]->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398}
2399
2400// Test that PeerConnection methods fails gracefully after
2401// PeerConnection::Close has been called.
2402TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002403 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2405 CreateOfferAsRemoteDescription();
2406 CreateAnswerAsLocalDescription();
2407
2408 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002409 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410 pc_->local_streams()->at(0);
2411
2412 pc_->Close();
2413
2414 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002415 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416
2417 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002418 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002420 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421
2422 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2423
2424 EXPECT_TRUE(pc_->local_description() != NULL);
2425 EXPECT_TRUE(pc_->remote_description() != NULL);
2426
kwibergd1fe2812016-04-27 06:47:29 -07002427 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07002428 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002429 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07002430 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431
2432 std::string sdp;
2433 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2434 SessionDescriptionInterface* remote_offer =
2435 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2436 sdp, NULL);
2437 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
2438
2439 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2440 SessionDescriptionInterface* local_offer =
2441 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2442 sdp, NULL);
2443 EXPECT_FALSE(DoSetLocalDescription(local_offer));
2444}
2445
2446// Test that GetStats can still be called after PeerConnection::Close.
2447TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
2448 InitiateCall();
2449 pc_->Close();
2450 DoGetStats(NULL);
2451}
deadbeefab9b2d12015-10-14 11:33:11 -07002452
2453// NOTE: The series of tests below come from what used to be
2454// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2455// setting a remote or local description has the expected effects.
2456
2457// This test verifies that the remote MediaStreams corresponding to a received
2458// SDP string is created. In this test the two separate MediaStreams are
2459// signaled.
2460TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2461 FakeConstraints constraints;
2462 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2463 true);
2464 CreatePeerConnection(&constraints);
2465 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2466
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002467 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002468 EXPECT_TRUE(
2469 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2470 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2471 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2472
2473 // Create a session description based on another SDP with another
2474 // MediaStream.
2475 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
2476
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002477 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002478 EXPECT_TRUE(
2479 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2480}
2481
2482// This test verifies that when remote tracks are added/removed from SDP, the
2483// created remote streams are updated appropriately.
2484TEST_F(PeerConnectionInterfaceTest,
2485 AddRemoveTrackFromExistingRemoteMediaStream) {
2486 FakeConstraints constraints;
2487 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2488 true);
2489 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002490 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002491 CreateSessionDescriptionAndReference(1, 1);
deadbeefab9b2d12015-10-14 11:33:11 -07002492 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
2493 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2494 reference_collection_));
2495
2496 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002497 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002498 CreateSessionDescriptionAndReference(2, 2);
deadbeefab9b2d12015-10-14 11:33:11 -07002499 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
2500 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2501 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002502 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002503 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2504 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002505 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002506 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2507 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002508
2509 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002510 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002511 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002512 MockTrackObserver audio_track_observer(audio_track2);
2513 MockTrackObserver video_track_observer(video_track2);
2514
2515 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2516 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
deadbeefab9b2d12015-10-14 11:33:11 -07002517 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
2518 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2519 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002520 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002521 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002522 audio_track2->state(), kTimeout);
2523 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2524 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002525}
2526
2527// This tests that remote tracks are ended if a local session description is set
2528// that rejects the media content type.
2529TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
2530 FakeConstraints constraints;
2531 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2532 true);
2533 CreatePeerConnection(&constraints);
2534 // First create and set a remote offer, then reject its video content in our
2535 // answer.
2536 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2537 ASSERT_EQ(1u, observer_.remote_streams()->count());
2538 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2539 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2540 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2541
2542 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
2543 remote_stream->GetVideoTracks()[0];
2544 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
2545 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
2546 remote_stream->GetAudioTracks()[0];
2547 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2548
kwibergd1fe2812016-04-27 06:47:29 -07002549 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002550 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002551 cricket::ContentInfo* video_info =
2552 local_answer->description()->GetContentByName("video");
2553 video_info->rejected = true;
2554 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2555 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2556 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2557
2558 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002559 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002560 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002561 video_info = local_offer->description()->GetContentByName("video");
2562 ASSERT_TRUE(video_info != nullptr);
2563 video_info->rejected = true;
2564 cricket::ContentInfo* audio_info =
2565 local_offer->description()->GetContentByName("audio");
2566 ASSERT_TRUE(audio_info != nullptr);
2567 audio_info->rejected = true;
2568 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002569 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002570 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002571 remote_audio->state(), kTimeout);
2572 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2573 remote_video->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002574}
2575
2576// This tests that we won't crash if the remote track has been removed outside
2577// of PeerConnection and then PeerConnection tries to reject the track.
2578TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2579 FakeConstraints constraints;
2580 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2581 true);
2582 CreatePeerConnection(&constraints);
2583 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2584 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2585 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2586 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2587
kwibergd1fe2812016-04-27 06:47:29 -07002588 std::unique_ptr<SessionDescriptionInterface> local_answer(
deadbeefab9b2d12015-10-14 11:33:11 -07002589 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2590 kSdpStringWithStream1, nullptr));
2591 cricket::ContentInfo* video_info =
2592 local_answer->description()->GetContentByName("video");
2593 video_info->rejected = true;
2594 cricket::ContentInfo* audio_info =
2595 local_answer->description()->GetContentByName("audio");
2596 audio_info->rejected = true;
2597 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2598
2599 // No crash is a pass.
2600}
2601
deadbeef5e97fb52015-10-15 12:49:08 -07002602// This tests that if a recvonly remote description is set, no remote streams
2603// will be created, even if the description contains SSRCs/MSIDs.
2604// See: https://code.google.com/p/webrtc/issues/detail?id=5054
2605TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2606 FakeConstraints constraints;
2607 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2608 true);
2609 CreatePeerConnection(&constraints);
2610
2611 std::string recvonly_offer = kSdpStringWithStream1;
2612 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2613 strlen(kRecvonly), &recvonly_offer);
2614 CreateAndSetRemoteOffer(recvonly_offer);
2615
2616 EXPECT_EQ(0u, observer_.remote_streams()->count());
2617}
2618
deadbeefab9b2d12015-10-14 11:33:11 -07002619// This tests that a default MediaStream is created if a remote session
2620// description doesn't contain any streams and no MSID support.
2621// It also tests that the default stream is updated if a video m-line is added
2622// in a subsequent session description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002623TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002624 FakeConstraints constraints;
2625 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2626 true);
2627 CreatePeerConnection(&constraints);
2628 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2629
2630 ASSERT_EQ(1u, observer_.remote_streams()->count());
2631 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2632
2633 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2634 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2635 EXPECT_EQ("default", remote_stream->label());
2636
2637 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2638 ASSERT_EQ(1u, observer_.remote_streams()->count());
2639 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2640 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002641 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2642 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002643 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2644 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002645 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2646 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002647}
2648
2649// This tests that a default MediaStream is created if a remote session
2650// description doesn't contain any streams and media direction is send only.
2651TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002652 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002653 FakeConstraints constraints;
2654 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2655 true);
2656 CreatePeerConnection(&constraints);
2657 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2658
2659 ASSERT_EQ(1u, observer_.remote_streams()->count());
2660 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2661
2662 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2663 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2664 EXPECT_EQ("default", remote_stream->label());
2665}
2666
2667// This tests that it won't crash when PeerConnection tries to remove
2668// a remote track that as already been removed from the MediaStream.
2669TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2670 FakeConstraints constraints;
2671 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2672 true);
2673 CreatePeerConnection(&constraints);
2674 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2675 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2676 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2677 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2678
2679 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2680
2681 // No crash is a pass.
2682}
2683
2684// This tests that a default MediaStream is created if the remote session
2685// description doesn't contain any streams and don't contain an indication if
2686// MSID is supported.
2687TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002688 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002689 FakeConstraints constraints;
2690 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2691 true);
2692 CreatePeerConnection(&constraints);
2693 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2694
2695 ASSERT_EQ(1u, observer_.remote_streams()->count());
2696 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2697 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2698 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2699}
2700
2701// This tests that a default MediaStream is not created if the remote session
2702// description doesn't contain any streams but does support MSID.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002703TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002704 FakeConstraints constraints;
2705 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2706 true);
2707 CreatePeerConnection(&constraints);
2708 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2709 EXPECT_EQ(0u, observer_.remote_streams()->count());
2710}
2711
deadbeefbda7e0b2015-12-08 17:13:40 -08002712// This tests that when setting a new description, the old default tracks are
2713// not destroyed and recreated.
2714// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Stefan Holmer102362b2016-03-18 09:39:07 +01002715TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002716 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08002717 FakeConstraints constraints;
2718 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2719 true);
2720 CreatePeerConnection(&constraints);
2721 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2722
2723 ASSERT_EQ(1u, observer_.remote_streams()->count());
2724 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2725 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2726
2727 // Set the track to "disabled", then set a new description and ensure the
2728 // track is still disabled, which ensures it hasn't been recreated.
2729 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2730 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2731 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2732 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2733}
2734
deadbeefab9b2d12015-10-14 11:33:11 -07002735// This tests that a default MediaStream is not created if a remote session
2736// description is updated to not have any MediaStreams.
2737TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2738 FakeConstraints constraints;
2739 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2740 true);
2741 CreatePeerConnection(&constraints);
2742 CreateAndSetRemoteOffer(kSdpStringWithStream1);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002743 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002744 EXPECT_TRUE(
2745 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2746
2747 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2748 EXPECT_EQ(0u, observer_.remote_streams()->count());
2749}
2750
2751// This tests that an RtpSender is created when the local description is set
2752// after adding a local stream.
2753// TODO(deadbeef): This test and the one below it need to be updated when
2754// an RtpSender's lifetime isn't determined by when a local description is set.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002755TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002756 FakeConstraints constraints;
2757 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2758 true);
2759 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002760
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002761 // Create an offer with 1 stream with 2 tracks of each type.
2762 rtc::scoped_refptr<StreamCollection> stream_collection =
2763 CreateStreamCollection(1, 2);
2764 pc_->AddStream(stream_collection->at(0));
2765 std::unique_ptr<SessionDescriptionInterface> offer;
2766 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2767 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002768
deadbeefab9b2d12015-10-14 11:33:11 -07002769 auto senders = pc_->GetSenders();
2770 EXPECT_EQ(4u, senders.size());
2771 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2772 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2773 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2774 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2775
2776 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002777 pc_->RemoveStream(stream_collection->at(0));
2778 stream_collection = CreateStreamCollection(1, 1);
2779 pc_->AddStream(stream_collection->at(0));
2780 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2781 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2782
deadbeefab9b2d12015-10-14 11:33:11 -07002783 senders = pc_->GetSenders();
2784 EXPECT_EQ(2u, senders.size());
2785 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2786 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2787 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2788 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2789}
2790
2791// This tests that an RtpSender is created when the local description is set
2792// before adding a local stream.
2793TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002794 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002795 FakeConstraints constraints;
2796 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2797 true);
2798 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002799
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002800 rtc::scoped_refptr<StreamCollection> stream_collection =
2801 CreateStreamCollection(1, 2);
2802 // Add a stream to create the offer, but remove it afterwards.
2803 pc_->AddStream(stream_collection->at(0));
2804 std::unique_ptr<SessionDescriptionInterface> offer;
2805 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2806 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002807
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002808 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002809 auto senders = pc_->GetSenders();
2810 EXPECT_EQ(0u, senders.size());
2811
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002812 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002813 senders = pc_->GetSenders();
2814 EXPECT_EQ(4u, senders.size());
2815 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2816 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2817 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2818 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2819}
2820
2821// This tests that the expected behavior occurs if the SSRC on a local track is
2822// changed when SetLocalDescription is called.
2823TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002824 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07002825 FakeConstraints constraints;
2826 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2827 true);
2828 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002829
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002830 rtc::scoped_refptr<StreamCollection> stream_collection =
2831 CreateStreamCollection(2, 1);
2832 pc_->AddStream(stream_collection->at(0));
2833 std::unique_ptr<SessionDescriptionInterface> offer;
2834 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2835 // Grab a copy of the offer before it gets passed into the PC.
2836 std::unique_ptr<JsepSessionDescription> modified_offer(
2837 new JsepSessionDescription(JsepSessionDescription::kOffer));
2838 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
2839 offer->session_version());
2840 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002841
deadbeefab9b2d12015-10-14 11:33:11 -07002842 auto senders = pc_->GetSenders();
2843 EXPECT_EQ(2u, senders.size());
2844 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2845 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2846
2847 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002848 cricket::MediaContentDescription* desc =
2849 cricket::GetFirstAudioContentDescription(modified_offer->description());
2850 ASSERT_TRUE(desc != NULL);
2851 for (StreamParams& stream : desc->mutable_streams()) {
2852 for (unsigned int& ssrc : stream.ssrcs) {
2853 ++ssrc;
2854 }
2855 }
deadbeefab9b2d12015-10-14 11:33:11 -07002856
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002857 desc =
2858 cricket::GetFirstVideoContentDescription(modified_offer->description());
2859 ASSERT_TRUE(desc != NULL);
2860 for (StreamParams& stream : desc->mutable_streams()) {
2861 for (unsigned int& ssrc : stream.ssrcs) {
2862 ++ssrc;
2863 }
2864 }
2865
2866 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002867 senders = pc_->GetSenders();
2868 EXPECT_EQ(2u, senders.size());
2869 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2870 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2871 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2872 // changed.
2873}
2874
2875// This tests that the expected behavior occurs if a new session description is
2876// set with the same tracks, but on a different MediaStream.
Stefan Holmer55d6e7c2016-03-17 16:26:40 +01002877TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002878 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002879 FakeConstraints constraints;
2880 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2881 true);
2882 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002883
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002884 rtc::scoped_refptr<StreamCollection> stream_collection =
2885 CreateStreamCollection(2, 1);
2886 pc_->AddStream(stream_collection->at(0));
2887 std::unique_ptr<SessionDescriptionInterface> offer;
2888 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2889 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002890
deadbeefab9b2d12015-10-14 11:33:11 -07002891 auto senders = pc_->GetSenders();
2892 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002893 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2894 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002895
2896 // Add a new MediaStream but with the same tracks as in the first stream.
2897 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2898 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002899 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2900 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002901 pc_->AddStream(stream_1);
2902
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002903 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2904 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002905
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002906 auto new_senders = pc_->GetSenders();
2907 // Should be the same senders as before, but with updated stream id.
2908 // Note that this behavior is subject to change in the future.
2909 // We may decide the PC should ignore existing tracks in AddStream.
2910 EXPECT_EQ(senders, new_senders);
2911 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2912 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002913}
2914
zhihuang81c3a032016-11-17 12:06:24 -08002915// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
2916TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) {
2917 FakeConstraints constraints;
2918 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2919 true);
2920 CreatePeerConnection(&constraints);
2921 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2922 EXPECT_EQ(observer_.num_added_tracks_, 1);
2923 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2924
2925 // Create and set the updated remote SDP.
2926 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2927 EXPECT_EQ(observer_.num_added_tracks_, 2);
2928 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2929}
2930
deadbeefd1a38b52016-12-10 13:15:33 -08002931// Test that when SetConfiguration is called and the configuration is
2932// changing, the next offer causes an ICE restart.
2933TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingIceRetart) {
2934 PeerConnectionInterface::RTCConfiguration config;
2935 config.type = PeerConnectionInterface::kRelay;
2936 // Need to pass default constraints to prevent disabling of DTLS...
2937 FakeConstraints default_constraints;
2938 CreatePeerConnection(config, &default_constraints);
2939 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2940
2941 // Do initial offer/answer so there's something to restart.
2942 CreateOfferAsLocalDescription();
2943 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2944
2945 // Grab the ufrags.
2946 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2947
2948 // Change ICE policy, which should trigger an ICE restart on the next offer.
2949 config.type = PeerConnectionInterface::kAll;
2950 EXPECT_TRUE(pc_->SetConfiguration(config));
2951 CreateOfferAsLocalDescription();
2952
2953 // Grab the new ufrags.
2954 std::vector<std::string> subsequent_ufrags =
2955 GetUfrags(pc_->local_description());
2956
2957 // Sanity check.
2958 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
2959 // Check that each ufrag is different.
2960 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
2961 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
2962 }
2963}
2964
2965// Test that when SetConfiguration is called and the configuration *isn't*
2966// changing, the next offer does *not* cause an ICE restart.
2967TEST_F(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRetart) {
2968 PeerConnectionInterface::RTCConfiguration config;
2969 config.type = PeerConnectionInterface::kRelay;
2970 // Need to pass default constraints to prevent disabling of DTLS...
2971 FakeConstraints default_constraints;
2972 CreatePeerConnection(config, &default_constraints);
2973 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2974
2975 // Do initial offer/answer so there's something to restart.
2976 CreateOfferAsLocalDescription();
2977 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2978
2979 // Grab the ufrags.
2980 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2981
2982 // Call SetConfiguration with a config identical to what the PC was
2983 // constructed with.
2984 EXPECT_TRUE(pc_->SetConfiguration(config));
2985 CreateOfferAsLocalDescription();
2986
2987 // Grab the new ufrags.
2988 std::vector<std::string> subsequent_ufrags =
2989 GetUfrags(pc_->local_description());
2990
2991 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
2992}
2993
2994// Test for a weird corner case scenario:
2995// 1. Audio/video session established.
2996// 2. SetConfiguration changes ICE config; ICE restart needed.
2997// 3. ICE restart initiated by remote peer, but only for one m= section.
2998// 4. Next createOffer should initiate an ICE restart, but only for the other
2999// m= section; it would be pointless to do an ICE restart for the m= section
3000// that was already restarted.
3001TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
3002 PeerConnectionInterface::RTCConfiguration config;
3003 config.type = PeerConnectionInterface::kRelay;
3004 // Need to pass default constraints to prevent disabling of DTLS...
3005 FakeConstraints default_constraints;
3006 CreatePeerConnection(config, &default_constraints);
3007 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
3008
3009 // Do initial offer/answer so there's something to restart.
3010 CreateOfferAsLocalDescription();
3011 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
3012
3013 // Change ICE policy, which should set the "needs-ice-restart" flag.
3014 config.type = PeerConnectionInterface::kAll;
3015 EXPECT_TRUE(pc_->SetConfiguration(config));
3016
3017 // Do ICE restart for the first m= section, initiated by remote peer.
3018 webrtc::JsepSessionDescription* remote_offer =
3019 new webrtc::JsepSessionDescription(SessionDescriptionInterface::kOffer);
3020 EXPECT_TRUE(remote_offer->Initialize(kSdpStringWithStream1, nullptr));
3021 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3022 "modified";
3023 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3024 CreateAnswerAsLocalDescription();
3025
3026 // Grab the ufrags.
3027 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3028 ASSERT_EQ(2, initial_ufrags.size());
3029
3030 // Create offer and grab the new ufrags.
3031 CreateOfferAsLocalDescription();
3032 std::vector<std::string> subsequent_ufrags =
3033 GetUfrags(pc_->local_description());
3034 ASSERT_EQ(2, subsequent_ufrags.size());
3035
3036 // Ensure that only the ufrag for the second m= section changed.
3037 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3038 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3039}
3040
deadbeeffe4a8a42016-12-20 17:56:17 -08003041// Tests that the methods to return current/pending descriptions work as
3042// expected at different points in the offer/answer exchange. This test does
3043// one offer/answer exchange as the offerer, then another as the answerer.
3044TEST_F(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
3045 // This disables DTLS so we can apply an answer to ourselves.
3046 CreatePeerConnection();
3047
3048 // Create initial local offer and get SDP (which will also be used as
3049 // answer/pranswer);
3050 std::unique_ptr<SessionDescriptionInterface> offer;
3051 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3052 std::string sdp;
3053 EXPECT_TRUE(offer->ToString(&sdp));
3054
3055 // Set local offer.
3056 SessionDescriptionInterface* local_offer = offer.release();
3057 EXPECT_TRUE(DoSetLocalDescription(local_offer));
3058 EXPECT_EQ(local_offer, pc_->pending_local_description());
3059 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3060 EXPECT_EQ(nullptr, pc_->current_local_description());
3061 EXPECT_EQ(nullptr, pc_->current_remote_description());
3062
3063 // Set remote pranswer.
3064 SessionDescriptionInterface* remote_pranswer =
3065 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3066 sdp, nullptr);
3067 EXPECT_TRUE(DoSetRemoteDescription(remote_pranswer));
3068 EXPECT_EQ(local_offer, pc_->pending_local_description());
3069 EXPECT_EQ(remote_pranswer, pc_->pending_remote_description());
3070 EXPECT_EQ(nullptr, pc_->current_local_description());
3071 EXPECT_EQ(nullptr, pc_->current_remote_description());
3072
3073 // Set remote answer.
3074 SessionDescriptionInterface* remote_answer = webrtc::CreateSessionDescription(
3075 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3076 EXPECT_TRUE(DoSetRemoteDescription(remote_answer));
3077 EXPECT_EQ(nullptr, pc_->pending_local_description());
3078 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3079 EXPECT_EQ(local_offer, pc_->current_local_description());
3080 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3081
3082 // Set remote offer.
3083 SessionDescriptionInterface* remote_offer = webrtc::CreateSessionDescription(
3084 SessionDescriptionInterface::kOffer, sdp, nullptr);
3085 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3086 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3087 EXPECT_EQ(nullptr, pc_->pending_local_description());
3088 EXPECT_EQ(local_offer, pc_->current_local_description());
3089 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3090
3091 // Set local pranswer.
3092 SessionDescriptionInterface* local_pranswer =
3093 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3094 sdp, nullptr);
3095 EXPECT_TRUE(DoSetLocalDescription(local_pranswer));
3096 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3097 EXPECT_EQ(local_pranswer, pc_->pending_local_description());
3098 EXPECT_EQ(local_offer, pc_->current_local_description());
3099 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3100
3101 // Set local answer.
3102 SessionDescriptionInterface* local_answer = webrtc::CreateSessionDescription(
3103 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3104 EXPECT_TRUE(DoSetLocalDescription(local_answer));
3105 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3106 EXPECT_EQ(nullptr, pc_->pending_local_description());
3107 EXPECT_EQ(remote_offer, pc_->current_remote_description());
3108 EXPECT_EQ(local_answer, pc_->current_local_description());
3109}
3110
nisse51542be2016-02-12 02:27:06 -08003111class PeerConnectionMediaConfigTest : public testing::Test {
3112 protected:
3113 void SetUp() override {
nisseaf510af2016-03-21 08:20:42 -07003114 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
nisse51542be2016-02-12 02:27:06 -08003115 pcf_->Initialize();
3116 }
3117 const cricket::MediaConfig& TestCreatePeerConnection(
3118 const PeerConnectionInterface::RTCConfiguration& config,
3119 const MediaConstraintsInterface *constraints) {
3120 pcf_->create_media_controller_called_ = false;
3121
zhihuang9763d562016-08-05 11:14:50 -07003122 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3123 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003124 EXPECT_TRUE(pc.get());
3125 EXPECT_TRUE(pcf_->create_media_controller_called_);
3126 return pcf_->create_media_controller_config_;
3127 }
3128
zhihuang9763d562016-08-05 11:14:50 -07003129 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003130 MockPeerConnectionObserver observer_;
3131};
3132
3133// This test verifies the default behaviour with no constraints and a
3134// default RTCConfiguration.
3135TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3136 PeerConnectionInterface::RTCConfiguration config;
3137 FakeConstraints constraints;
3138
3139 const cricket::MediaConfig& media_config =
3140 TestCreatePeerConnection(config, &constraints);
3141
3142 EXPECT_FALSE(media_config.enable_dscp);
nisse0db023a2016-03-01 04:29:59 -08003143 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection);
3144 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing);
3145 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003146}
3147
3148// This test verifies the DSCP constraint is recognized and passed to
3149// the CreateMediaController call.
3150TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
3151 PeerConnectionInterface::RTCConfiguration config;
3152 FakeConstraints constraints;
3153
3154 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
3155 const cricket::MediaConfig& media_config =
3156 TestCreatePeerConnection(config, &constraints);
3157
3158 EXPECT_TRUE(media_config.enable_dscp);
3159}
3160
3161// This test verifies the cpu overuse detection constraint is
3162// recognized and passed to the CreateMediaController call.
3163TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
3164 PeerConnectionInterface::RTCConfiguration config;
3165 FakeConstraints constraints;
3166
3167 constraints.AddOptional(
3168 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
3169 const cricket::MediaConfig media_config =
3170 TestCreatePeerConnection(config, &constraints);
3171
nisse0db023a2016-03-01 04:29:59 -08003172 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection);
nisse51542be2016-02-12 02:27:06 -08003173}
3174
3175// This test verifies that the disable_prerenderer_smoothing flag is
3176// propagated from RTCConfiguration to the CreateMediaController call.
3177TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3178 PeerConnectionInterface::RTCConfiguration config;
3179 FakeConstraints constraints;
3180
Niels Möller71bdda02016-03-31 12:59:59 +02003181 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08003182 const cricket::MediaConfig& media_config =
3183 TestCreatePeerConnection(config, &constraints);
3184
nisse0db023a2016-03-01 04:29:59 -08003185 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing);
3186}
3187
3188// This test verifies the suspend below min bitrate constraint is
3189// recognized and passed to the CreateMediaController call.
3190TEST_F(PeerConnectionMediaConfigTest,
3191 TestSuspendBelowMinBitrateConstraintTrue) {
3192 PeerConnectionInterface::RTCConfiguration config;
3193 FakeConstraints constraints;
3194
3195 constraints.AddOptional(
3196 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3197 true);
3198 const cricket::MediaConfig media_config =
3199 TestCreatePeerConnection(config, &constraints);
3200
3201 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003202}
3203
deadbeefab9b2d12015-10-14 11:33:11 -07003204// The following tests verify that session options are created correctly.
deadbeefc80741f2015-10-22 13:14:45 -07003205// TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
3206// "verify options are converted correctly", should be "pass options into
3207// CreateOffer and verify the correct offer is produced."
deadbeefab9b2d12015-10-14 11:33:11 -07003208
3209TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
3210 RTCOfferAnswerOptions rtc_options;
3211 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3212
3213 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003214 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003215
3216 rtc_options.offer_to_receive_audio =
3217 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003218 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003219}
3220
3221TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
3222 RTCOfferAnswerOptions rtc_options;
3223 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3224
3225 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003226 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003227
3228 rtc_options.offer_to_receive_video =
3229 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003230 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003231}
3232
3233// Test that a MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003234// OfferToReceiveAudio and OfferToReceiveVideo options are set.
deadbeefab9b2d12015-10-14 11:33:11 -07003235TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
3236 RTCOfferAnswerOptions rtc_options;
3237 rtc_options.offer_to_receive_audio = 1;
3238 rtc_options.offer_to_receive_video = 1;
3239
3240 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003241 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003242 EXPECT_TRUE(options.has_audio());
3243 EXPECT_TRUE(options.has_video());
3244 EXPECT_TRUE(options.bundle_enabled);
3245}
3246
3247// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003248// OfferToReceiveAudio is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003249TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
3250 RTCOfferAnswerOptions rtc_options;
3251 rtc_options.offer_to_receive_audio = 1;
3252
3253 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003254 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003255 EXPECT_TRUE(options.has_audio());
3256 EXPECT_FALSE(options.has_video());
3257 EXPECT_TRUE(options.bundle_enabled);
3258}
3259
3260// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003261// the default OfferOptions are used.
deadbeefab9b2d12015-10-14 11:33:11 -07003262TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
3263 RTCOfferAnswerOptions rtc_options;
3264
3265 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003266 options.transport_options["audio"] = cricket::TransportOptions();
3267 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003268 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefc80741f2015-10-22 13:14:45 -07003269 EXPECT_TRUE(options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07003270 EXPECT_FALSE(options.has_video());
deadbeefc80741f2015-10-22 13:14:45 -07003271 EXPECT_TRUE(options.bundle_enabled);
deadbeefab9b2d12015-10-14 11:33:11 -07003272 EXPECT_TRUE(options.vad_enabled);
deadbeef0ed85b22016-02-23 17:24:52 -08003273 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3274 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003275}
3276
3277// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003278// OfferToReceiveVideo is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003279TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
3280 RTCOfferAnswerOptions rtc_options;
3281 rtc_options.offer_to_receive_audio = 0;
3282 rtc_options.offer_to_receive_video = 1;
3283
3284 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003285 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003286 EXPECT_FALSE(options.has_audio());
3287 EXPECT_TRUE(options.has_video());
3288 EXPECT_TRUE(options.bundle_enabled);
3289}
3290
3291// Test that a correct MediaSessionOptions is created for an offer if
3292// UseRtpMux is set to false.
3293TEST(CreateSessionOptionsTest,
3294 GetMediaSessionOptionsForOfferWithBundleDisabled) {
3295 RTCOfferAnswerOptions rtc_options;
3296 rtc_options.offer_to_receive_audio = 1;
3297 rtc_options.offer_to_receive_video = 1;
3298 rtc_options.use_rtp_mux = false;
3299
3300 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003301 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003302 EXPECT_TRUE(options.has_audio());
3303 EXPECT_TRUE(options.has_video());
3304 EXPECT_FALSE(options.bundle_enabled);
3305}
3306
3307// Test that a correct MediaSessionOptions is created to restart ice if
3308// IceRestart is set. It also tests that subsequent MediaSessionOptions don't
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003309// have |audio_transport_options.ice_restart| etc. set.
deadbeefab9b2d12015-10-14 11:33:11 -07003310TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
3311 RTCOfferAnswerOptions rtc_options;
3312 rtc_options.ice_restart = true;
3313
3314 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003315 options.transport_options["audio"] = cricket::TransportOptions();
3316 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003317 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003318 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
3319 EXPECT_TRUE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003320
3321 rtc_options = RTCOfferAnswerOptions();
htaaac2dea2016-03-10 13:35:55 -08003322 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003323 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3324 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003325}
3326
3327// Test that the MediaConstraints in an answer don't affect if audio and video
3328// is offered in an offer but that if kOfferToReceiveAudio or
3329// kOfferToReceiveVideo constraints are true in an offer, the media type will be
3330// included in subsequent answers.
3331TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
3332 FakeConstraints answer_c;
3333 answer_c.SetMandatoryReceiveAudio(true);
3334 answer_c.SetMandatoryReceiveVideo(true);
3335
3336 cricket::MediaSessionOptions answer_options;
3337 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
3338 EXPECT_TRUE(answer_options.has_audio());
3339 EXPECT_TRUE(answer_options.has_video());
3340
deadbeefc80741f2015-10-22 13:14:45 -07003341 RTCOfferAnswerOptions rtc_offer_options;
deadbeefab9b2d12015-10-14 11:33:11 -07003342
3343 cricket::MediaSessionOptions offer_options;
htaaac2dea2016-03-10 13:35:55 -08003344 EXPECT_TRUE(
3345 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
deadbeefc80741f2015-10-22 13:14:45 -07003346 EXPECT_TRUE(offer_options.has_audio());
htaaac2dea2016-03-10 13:35:55 -08003347 EXPECT_TRUE(offer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003348
deadbeefc80741f2015-10-22 13:14:45 -07003349 RTCOfferAnswerOptions updated_rtc_offer_options;
3350 updated_rtc_offer_options.offer_to_receive_audio = 1;
3351 updated_rtc_offer_options.offer_to_receive_video = 1;
deadbeefab9b2d12015-10-14 11:33:11 -07003352
3353 cricket::MediaSessionOptions updated_offer_options;
htaaac2dea2016-03-10 13:35:55 -08003354 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
htaa2a49d92016-03-04 02:51:39 -08003355 &updated_offer_options));
deadbeefab9b2d12015-10-14 11:33:11 -07003356 EXPECT_TRUE(updated_offer_options.has_audio());
3357 EXPECT_TRUE(updated_offer_options.has_video());
3358
3359 // Since an offer has been created with both audio and video, subsequent
3360 // offers and answers should contain both audio and video.
3361 // Answers will only contain the media types that exist in the offer
3362 // regardless of the value of |updated_answer_options.has_audio| and
3363 // |updated_answer_options.has_video|.
3364 FakeConstraints updated_answer_c;
3365 answer_c.SetMandatoryReceiveAudio(false);
3366 answer_c.SetMandatoryReceiveVideo(false);
3367
3368 cricket::MediaSessionOptions updated_answer_options;
3369 EXPECT_TRUE(
3370 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
3371 EXPECT_TRUE(updated_answer_options.has_audio());
3372 EXPECT_TRUE(updated_answer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003373}
deadbeef3edec7c2016-12-10 11:44:26 -08003374
deadbeef293e9262017-01-11 12:28:30 -08003375TEST(RTCErrorTypeTest, OstreamOperator) {
deadbeef3edec7c2016-12-10 11:44:26 -08003376 std::ostringstream oss;
deadbeef293e9262017-01-11 12:28:30 -08003377 oss << webrtc::RTCErrorType::NONE << ' '
3378 << webrtc::RTCErrorType::INVALID_PARAMETER << ' '
3379 << webrtc::RTCErrorType::INTERNAL_ERROR;
deadbeef3edec7c2016-12-10 11:44:26 -08003380 EXPECT_EQ("NONE INVALID_PARAMETER INTERNAL_ERROR", oss.str());
3381}
deadbeef293e9262017-01-11 12:28:30 -08003382
3383// Tests a few random fields being different.
3384TEST(RTCConfigurationTest, ComparisonOperators) {
3385 PeerConnectionInterface::RTCConfiguration a;
3386 PeerConnectionInterface::RTCConfiguration b;
3387 EXPECT_EQ(a, b);
3388
3389 PeerConnectionInterface::RTCConfiguration c;
3390 c.servers.push_back(PeerConnectionInterface::IceServer());
3391 EXPECT_NE(a, c);
3392
3393 PeerConnectionInterface::RTCConfiguration d;
3394 d.type = PeerConnectionInterface::kRelay;
3395 EXPECT_NE(a, d);
3396
3397 PeerConnectionInterface::RTCConfiguration e;
3398 e.audio_jitter_buffer_max_packets = 5;
3399 EXPECT_NE(a, e);
3400
3401 PeerConnectionInterface::RTCConfiguration f;
3402 f.ice_connection_receiving_timeout = 1337;
3403 EXPECT_NE(a, f);
3404
3405 PeerConnectionInterface::RTCConfiguration g;
3406 g.disable_ipv6 = true;
3407 EXPECT_NE(a, g);
3408
3409 PeerConnectionInterface::RTCConfiguration h(
3410 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3411 EXPECT_NE(a, h);
3412}