blob: e90fdd3e8dc5494101a0fe7b91fc3a46aeff0377 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080012#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080014#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/jsepsessiondescription.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/mediastreaminterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/peerconnectioninterface.h"
19#include "webrtc/api/rtpreceiverinterface.h"
20#include "webrtc/api/rtpsenderinterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010021#include "webrtc/api/test/fakeconstraints.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000022#include "webrtc/base/gunit.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000023#include "webrtc/base/ssladapter.h"
24#include "webrtc/base/sslstreamadapter.h"
25#include "webrtc/base/stringutils.h"
26#include "webrtc/base/thread.h"
kjellandera96e2d72016-02-04 23:52:28 -080027#include "webrtc/media/base/fakevideocapturer.h"
deadbeef953c2ce2017-01-09 14:53:41 -080028#include "webrtc/media/sctp/sctptransportinternal.h"
kwiberg1e4e8cb2017-01-31 01:48:08 -080029#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070030#include "webrtc/p2p/base/fakeportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010032#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080033#include "webrtc/pc/mediastream.h"
34#include "webrtc/pc/peerconnection.h"
35#include "webrtc/pc/streamcollection.h"
36#include "webrtc/pc/test/fakertccertificategenerator.h"
37#include "webrtc/pc/test/fakevideotracksource.h"
38#include "webrtc/pc/test/mockpeerconnectionobservers.h"
39#include "webrtc/pc/test/testsdpstrings.h"
40#include "webrtc/pc/videocapturertracksource.h"
41#include "webrtc/pc/videotrack.h"
kwibergac9f8762016-09-30 22:29:43 -070042#include "webrtc/test/gmock.h"
43
44#ifdef WEBRTC_ANDROID
ossu7bb87ee2017-01-23 04:56:25 -080045#include "webrtc/pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070046#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48static const char kStreamLabel1[] = "local_stream_1";
49static const char kStreamLabel2[] = "local_stream_2";
50static const char kStreamLabel3[] = "local_stream_3";
51static const int kDefaultStunPort = 3478;
52static const char kStunAddressOnly[] = "stun:address";
53static const char kStunInvalidPort[] = "stun:address:-1";
54static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
55static const char kStunAddressPortAndMore2[] = "stun:address:port more";
56static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
57static const char kTurnUsername[] = "user";
58static const char kTurnPassword[] = "password";
59static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020060static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
deadbeefab9b2d12015-10-14 11:33:11 -070062static const char kStreams[][8] = {"stream1", "stream2"};
63static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
64static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
65
deadbeef5e97fb52015-10-15 12:49:08 -070066static const char kRecvonly[] = "recvonly";
67static const char kSendrecv[] = "sendrecv";
68
deadbeefab9b2d12015-10-14 11:33:11 -070069// Reference SDP with a MediaStream with label "stream1" and audio track with
70// id "audio_1" and a video track with id "video_1;
71static const char kSdpStringWithStream1[] =
72 "v=0\r\n"
73 "o=- 0 0 IN IP4 127.0.0.1\r\n"
74 "s=-\r\n"
75 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080076 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070077 "a=ice-ufrag:e5785931\r\n"
78 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
79 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
80 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070081 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070082 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080083 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070084 "a=rtpmap:103 ISAC/16000\r\n"
85 "a=ssrc:1 cname:stream1\r\n"
86 "a=ssrc:1 mslabel:stream1\r\n"
87 "a=ssrc:1 label:audiotrack0\r\n"
88 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080089 "a=ice-ufrag:e5785931\r\n"
90 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
91 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
92 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070093 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070094 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080095 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070096 "a=rtpmap:120 VP8/90000\r\n"
97 "a=ssrc:2 cname:stream1\r\n"
98 "a=ssrc:2 mslabel:stream1\r\n"
99 "a=ssrc:2 label:videotrack0\r\n";
100
zhihuang81c3a032016-11-17 12:06:24 -0800101// Reference SDP with a MediaStream with label "stream1" and audio track with
102// id "audio_1";
103static const char kSdpStringWithStream1AudioTrackOnly[] =
104 "v=0\r\n"
105 "o=- 0 0 IN IP4 127.0.0.1\r\n"
106 "s=-\r\n"
107 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800108 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800109 "a=ice-ufrag:e5785931\r\n"
110 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
111 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
112 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800113 "a=mid:audio\r\n"
114 "a=sendrecv\r\n"
115 "a=rtpmap:103 ISAC/16000\r\n"
116 "a=ssrc:1 cname:stream1\r\n"
117 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800118 "a=ssrc:1 label:audiotrack0\r\n"
119 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800120
deadbeefab9b2d12015-10-14 11:33:11 -0700121// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
122// MediaStreams have one audio track and one video track.
123// This uses MSID.
124static const char kSdpStringWithStream1And2[] =
125 "v=0\r\n"
126 "o=- 0 0 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800129 "a=msid-semantic: WMS stream1 stream2\r\n"
130 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700131 "a=ice-ufrag:e5785931\r\n"
132 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
133 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
134 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700136 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800137 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700138 "a=rtpmap:103 ISAC/16000\r\n"
139 "a=ssrc:1 cname:stream1\r\n"
140 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
141 "a=ssrc:3 cname:stream2\r\n"
142 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
143 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800144 "a=ice-ufrag:e5785931\r\n"
145 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
146 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
147 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700148 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700149 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800150 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700151 "a=rtpmap:120 VP8/0\r\n"
152 "a=ssrc:2 cname:stream1\r\n"
153 "a=ssrc:2 msid:stream1 videotrack0\r\n"
154 "a=ssrc:4 cname:stream2\r\n"
155 "a=ssrc:4 msid:stream2 videotrack1\r\n";
156
157// Reference SDP without MediaStreams. Msid is not supported.
158static const char kSdpStringWithoutStreams[] =
159 "v=0\r\n"
160 "o=- 0 0 IN IP4 127.0.0.1\r\n"
161 "s=-\r\n"
162 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800163 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700164 "a=ice-ufrag:e5785931\r\n"
165 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
166 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
167 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700168 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700169 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800170 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700171 "a=rtpmap:103 ISAC/16000\r\n"
172 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800173 "a=ice-ufrag:e5785931\r\n"
174 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
175 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
176 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700177 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700178 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800179 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700180 "a=rtpmap:120 VP8/90000\r\n";
181
182// Reference SDP without MediaStreams. Msid is supported.
183static const char kSdpStringWithMsidWithoutStreams[] =
184 "v=0\r\n"
185 "o=- 0 0 IN IP4 127.0.0.1\r\n"
186 "s=-\r\n"
187 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800188 "a=msid-semantic: WMS\r\n"
189 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700190 "a=ice-ufrag:e5785931\r\n"
191 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
192 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
193 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700194 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700195 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800196 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700197 "a=rtpmap:103 ISAC/16000\r\n"
198 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800199 "a=ice-ufrag:e5785931\r\n"
200 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
201 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
202 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700203 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700204 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800205 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700206 "a=rtpmap:120 VP8/90000\r\n";
207
208// Reference SDP without MediaStreams and audio only.
209static const char kSdpStringWithoutStreamsAudioOnly[] =
210 "v=0\r\n"
211 "o=- 0 0 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800214 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700215 "a=ice-ufrag:e5785931\r\n"
216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700220 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800221 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700222 "a=rtpmap:103 ISAC/16000\r\n";
223
224// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
225static const char kSdpStringSendOnlyWithoutStreams[] =
226 "v=0\r\n"
227 "o=- 0 0 IN IP4 127.0.0.1\r\n"
228 "s=-\r\n"
229 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800230 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700231 "a=ice-ufrag:e5785931\r\n"
232 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
233 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
234 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700235 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700236 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700237 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800238 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700239 "a=rtpmap:103 ISAC/16000\r\n"
240 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800241 "a=ice-ufrag:e5785931\r\n"
242 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
243 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
244 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700245 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700246 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700247 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800248 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700249 "a=rtpmap:120 VP8/90000\r\n";
250
251static const char kSdpStringInit[] =
252 "v=0\r\n"
253 "o=- 0 0 IN IP4 127.0.0.1\r\n"
254 "s=-\r\n"
255 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700256 "a=msid-semantic: WMS\r\n";
257
258static const char kSdpStringAudio[] =
259 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800260 "a=ice-ufrag:e5785931\r\n"
261 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
262 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
263 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700264 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700265 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800266 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700267 "a=rtpmap:103 ISAC/16000\r\n";
268
269static const char kSdpStringVideo[] =
270 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800271 "a=ice-ufrag:e5785931\r\n"
272 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
273 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
274 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700275 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700276 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800277 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700278 "a=rtpmap:120 VP8/90000\r\n";
279
280static const char kSdpStringMs1Audio0[] =
281 "a=ssrc:1 cname:stream1\r\n"
282 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
283
284static const char kSdpStringMs1Video0[] =
285 "a=ssrc:2 cname:stream1\r\n"
286 "a=ssrc:2 msid:stream1 videotrack0\r\n";
287
288static const char kSdpStringMs1Audio1[] =
289 "a=ssrc:3 cname:stream1\r\n"
290 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
291
292static const char kSdpStringMs1Video1[] =
293 "a=ssrc:4 cname:stream1\r\n"
294 "a=ssrc:4 msid:stream1 videotrack1\r\n";
295
deadbeef8662f942017-01-20 21:20:51 -0800296static const char kDtlsSdesFallbackSdp[] =
297 "v=0\r\n"
298 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
299 "s=-\r\n"
300 "c=IN IP4 0.0.0.0\r\n"
301 "t=0 0\r\n"
302 "a=group:BUNDLE audio\r\n"
303 "a=msid-semantic: WMS\r\n"
304 "m=audio 1 RTP/SAVPF 0\r\n"
305 "a=sendrecv\r\n"
306 "a=rtcp-mux\r\n"
307 "a=mid:audio\r\n"
308 "a=ssrc:1 cname:stream1\r\n"
309 "a=ssrc:1 mslabel:stream1\r\n"
310 "a=ssrc:1 label:audiotrack0\r\n"
311 "a=ice-ufrag:e5785931\r\n"
312 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
313 "a=rtpmap:0 pcmu/8000\r\n"
314 "a=fingerprint:sha-1 "
315 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
316 "a=setup:actpass\r\n"
317 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
318 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
319 "dummy_session_params\r\n";
320
perkjd61bf802016-03-24 03:16:19 -0700321using ::testing::Exactly;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700322using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700324using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325using webrtc::AudioTrackInterface;
326using webrtc::DataBuffer;
327using webrtc::DataChannelInterface;
328using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329using webrtc::IceCandidateInterface;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700330using webrtc::JsepSessionDescription;
deadbeefc80741f2015-10-22 13:14:45 -0700331using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700332using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333using webrtc::MediaStreamInterface;
334using webrtc::MediaStreamTrackInterface;
335using webrtc::MockCreateSessionDescriptionObserver;
336using webrtc::MockDataChannelObserver;
337using webrtc::MockSetSessionDescriptionObserver;
338using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700339using webrtc::NotifierInterface;
340using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341using webrtc::PeerConnectionInterface;
342using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800343using webrtc::RTCError;
344using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700345using webrtc::RtpReceiverInterface;
346using webrtc::RtpSenderInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347using webrtc::SdpParseError;
348using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700349using webrtc::StreamCollection;
350using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100351using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700352using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353using webrtc::VideoTrackInterface;
354
deadbeefab9b2d12015-10-14 11:33:11 -0700355typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
356
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357namespace {
358
359// Gets the first ssrc of given content type from the ContentInfo.
360bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
361 if (!content_info || !ssrc) {
362 return false;
363 }
364 const cricket::MediaContentDescription* media_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000365 static_cast<const cricket::MediaContentDescription*>(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 content_info->description);
367 if (!media_desc || media_desc->streams().empty()) {
368 return false;
369 }
370 *ssrc = media_desc->streams().begin()->first_ssrc();
371 return true;
372}
373
deadbeefd1a38b52016-12-10 13:15:33 -0800374// Get the ufrags out of an SDP blob. Useful for testing ICE restart
375// behavior.
376std::vector<std::string> GetUfrags(
377 const webrtc::SessionDescriptionInterface* desc) {
378 std::vector<std::string> ufrags;
379 for (const cricket::TransportInfo& info :
380 desc->description()->transport_infos()) {
381 ufrags.push_back(info.description.ice_ufrag);
382 }
383 return ufrags;
384}
385
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386void SetSsrcToZero(std::string* sdp) {
387 const char kSdpSsrcAtribute[] = "a=ssrc:";
388 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
389 size_t ssrc_pos = 0;
390 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
391 std::string::npos) {
392 size_t end_ssrc = sdp->find(" ", ssrc_pos);
393 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
394 ssrc_pos = end_ssrc;
395 }
396}
397
deadbeefab9b2d12015-10-14 11:33:11 -0700398// Check if |streams| contains the specified track.
399bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
400 const std::string& stream_label,
401 const std::string& track_id) {
402 for (const cricket::StreamParams& params : streams) {
403 if (params.sync_label == stream_label && params.id == track_id) {
404 return true;
405 }
406 }
407 return false;
408}
409
410// Check if |senders| contains the specified sender, by id.
411bool ContainsSender(
412 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
413 const std::string& id) {
414 for (const auto& sender : senders) {
415 if (sender->id() == id) {
416 return true;
417 }
418 }
419 return false;
420}
421
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700422// Check if |senders| contains the specified sender, by id and stream id.
423bool ContainsSender(
424 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
425 const std::string& id,
426 const std::string& stream_id) {
427 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700428 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700429 return true;
430 }
431 }
432 return false;
433}
434
deadbeefab9b2d12015-10-14 11:33:11 -0700435// Create a collection of streams.
436// CreateStreamCollection(1) creates a collection that
437// correspond to kSdpStringWithStream1.
438// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
439rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700440 int number_of_streams,
441 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700442 rtc::scoped_refptr<StreamCollection> local_collection(
443 StreamCollection::Create());
444
445 for (int i = 0; i < number_of_streams; ++i) {
446 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
447 webrtc::MediaStream::Create(kStreams[i]));
448
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700449 for (int j = 0; j < tracks_per_stream; ++j) {
450 // Add a local audio track.
451 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
452 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
453 nullptr));
454 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700455
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700456 // Add a local video track.
457 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
458 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
459 webrtc::FakeVideoTrackSource::Create()));
460 stream->AddTrack(video_track);
461 }
deadbeefab9b2d12015-10-14 11:33:11 -0700462
463 local_collection->AddStream(stream);
464 }
465 return local_collection;
466}
467
468// Check equality of StreamCollections.
469bool CompareStreamCollections(StreamCollectionInterface* s1,
470 StreamCollectionInterface* s2) {
471 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
472 return false;
473 }
474
475 for (size_t i = 0; i != s1->count(); ++i) {
476 if (s1->at(i)->label() != s2->at(i)->label()) {
477 return false;
478 }
479 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
480 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
481 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
482 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
483
484 if (audio_tracks1.size() != audio_tracks2.size()) {
485 return false;
486 }
487 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
488 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
489 return false;
490 }
491 }
492 if (video_tracks1.size() != video_tracks2.size()) {
493 return false;
494 }
495 for (size_t j = 0; j != video_tracks1.size(); ++j) {
496 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
497 return false;
498 }
499 }
500 }
501 return true;
502}
503
perkjd61bf802016-03-24 03:16:19 -0700504// Helper class to test Observer.
505class MockTrackObserver : public ObserverInterface {
506 public:
507 explicit MockTrackObserver(NotifierInterface* notifier)
508 : notifier_(notifier) {
509 notifier_->RegisterObserver(this);
510 }
511
512 ~MockTrackObserver() { Unregister(); }
513
514 void Unregister() {
515 if (notifier_) {
516 notifier_->UnregisterObserver(this);
517 notifier_ = nullptr;
518 }
519 }
520
521 MOCK_METHOD0(OnChanged, void());
522
523 private:
524 NotifierInterface* notifier_;
525};
526
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527class MockPeerConnectionObserver : public PeerConnectionObserver {
528 public:
kjellander71a1b612016-11-07 01:18:08 -0800529 // We need these using declarations because there are two versions of each of
530 // the below methods and we only override one of them.
531 // TODO(deadbeef): Remove once there's only one version of the methods.
532 using PeerConnectionObserver::OnAddStream;
533 using PeerConnectionObserver::OnRemoveStream;
534 using PeerConnectionObserver::OnDataChannel;
535
deadbeefab9b2d12015-10-14 11:33:11 -0700536 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200537 virtual ~MockPeerConnectionObserver() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 }
539 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
540 pc_ = pc;
541 if (pc) {
542 state_ = pc_->signaling_state();
543 }
544 }
nisseef8b61e2016-04-29 06:09:15 -0700545 void OnSignalingChange(
546 PeerConnectionInterface::SignalingState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547 EXPECT_EQ(pc_->signaling_state(), new_state);
548 state_ = new_state;
549 }
550 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
551 virtual void OnStateChange(StateType state_changed) {
552 if (pc_.get() == NULL)
553 return;
554 switch (state_changed) {
555 case kSignalingState:
556 // OnSignalingChange and OnStateChange(kSignalingState) should always
557 // be called approximately simultaneously. To ease testing, we require
558 // that they always be called in that order. This check verifies
559 // that OnSignalingChange has just been called.
560 EXPECT_EQ(pc_->signaling_state(), state_);
561 break;
562 case kIceState:
563 ADD_FAILURE();
564 break;
565 default:
566 ADD_FAILURE();
567 break;
568 }
569 }
deadbeefab9b2d12015-10-14 11:33:11 -0700570
571 MediaStreamInterface* RemoteStream(const std::string& label) {
572 return remote_streams_->find(label);
573 }
574 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700575 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 last_added_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700577 remote_streams_->AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700579 void OnRemoveStream(
580 rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 last_removed_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700582 remote_streams_->RemoveStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 }
perkjdfb769d2016-02-09 03:09:43 -0800584 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700585 void OnDataChannel(
586 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 last_datachannel_ = data_channel;
588 }
589
perkjdfb769d2016-02-09 03:09:43 -0800590 void OnIceConnectionChange(
591 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 EXPECT_EQ(pc_->ice_connection_state(), new_state);
zhihuang81c3a032016-11-17 12:06:24 -0800593 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 }
perkjdfb769d2016-02-09 03:09:43 -0800595 void OnIceGatheringChange(
596 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
perkjdfb769d2016-02-09 03:09:43 -0800598 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete;
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 OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
603 pc_->ice_gathering_state());
604
605 std::string sdp;
606 EXPECT_TRUE(candidate->ToString(&sdp));
607 EXPECT_LT(0u, sdp.size());
608 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
609 candidate->sdp_mline_index(), sdp, NULL));
610 EXPECT_TRUE(last_candidate_.get() != NULL);
zhihuang81c3a032016-11-17 12:06:24 -0800611 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700612 }
613
614 void OnIceCandidatesRemoved(
615 const std::vector<cricket::Candidate>& candidates) override {
zhihuang81c3a032016-11-17 12:06:24 -0800616 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700617 }
618
619 void OnIceConnectionReceivingChange(bool receiving) override {
zhihuang81c3a032016-11-17 12:06:24 -0800620 callback_triggered_ = true;
621 }
622
zhihuangc63b8942016-12-02 15:41:10 -0800623 void OnAddTrack(
624 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
625 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
626 streams) override {
zhihuang81c3a032016-11-17 12:06:24 -0800627 EXPECT_TRUE(receiver != nullptr);
628 num_added_tracks_++;
629 last_added_track_label_ = receiver->id();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631
632 // Returns the label of the last added stream.
633 // Empty string if no stream have been added.
634 std::string GetLastAddedStreamLabel() {
635 if (last_added_stream_.get())
636 return last_added_stream_->label();
637 return "";
638 }
639 std::string GetLastRemovedStreamLabel() {
640 if (last_removed_stream_.get())
641 return last_removed_stream_->label();
642 return "";
643 }
644
zhihuang9763d562016-08-05 11:14:50 -0700645 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 PeerConnectionInterface::SignalingState state_;
kwibergd1fe2812016-04-27 06:47:29 -0700647 std::unique_ptr<IceCandidateInterface> last_candidate_;
zhihuang9763d562016-08-05 11:14:50 -0700648 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
deadbeefab9b2d12015-10-14 11:33:11 -0700649 rtc::scoped_refptr<StreamCollection> remote_streams_;
650 bool renegotiation_needed_ = false;
651 bool ice_complete_ = false;
zhihuang81c3a032016-11-17 12:06:24 -0800652 bool callback_triggered_ = false;
653 int num_added_tracks_ = 0;
654 std::string last_added_track_label_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655
656 private:
zhihuang9763d562016-08-05 11:14:50 -0700657 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
658 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659};
660
661} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700662
zhihuang29ff8442016-07-27 11:07:25 -0700663// The PeerConnectionMediaConfig tests below verify that configuration
664// and constraints are propagated into the MediaConfig passed to
665// CreateMediaController. These settings are intended for MediaChannel
666// constructors, but that is not exercised by these unittest.
667class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
668 public:
kwiberg1e4e8cb2017-01-31 01:48:08 -0800669 PeerConnectionFactoryForTest()
670 : webrtc::PeerConnectionFactory(
671 webrtc::CreateBuiltinAudioEncoderFactory(),
672 webrtc::CreateBuiltinAudioDecoderFactory()) {}
673
zhihuang29ff8442016-07-27 11:07:25 -0700674 webrtc::MediaControllerInterface* CreateMediaController(
skvlad11a9cbf2016-10-07 11:53:05 -0700675 const cricket::MediaConfig& config,
676 webrtc::RtcEventLog* event_log) const override {
zhihuang29ff8442016-07-27 11:07:25 -0700677 create_media_controller_called_ = true;
678 create_media_controller_config_ = config;
679
680 webrtc::MediaControllerInterface* mc =
skvlad11a9cbf2016-10-07 11:53:05 -0700681 PeerConnectionFactory::CreateMediaController(config, event_log);
zhihuang29ff8442016-07-27 11:07:25 -0700682 EXPECT_TRUE(mc != nullptr);
683 return mc;
684 }
685
686 cricket::TransportController* CreateTransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700687 cricket::PortAllocator* port_allocator,
688 bool redetermine_role_on_ice_restart) override {
zhihuang29ff8442016-07-27 11:07:25 -0700689 transport_controller = new cricket::TransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700690 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
691 redetermine_role_on_ice_restart);
zhihuang29ff8442016-07-27 11:07:25 -0700692 return transport_controller;
693 }
694
695 cricket::TransportController* transport_controller;
696 // Mutable, so they can be modified in the above const-declared method.
697 mutable bool create_media_controller_called_ = false;
698 mutable cricket::MediaConfig create_media_controller_config_;
699};
700
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701class PeerConnectionInterfaceTest : public testing::Test {
702 protected:
phoglund37ebcf02016-01-08 05:04:57 -0800703 PeerConnectionInterfaceTest() {
704#ifdef WEBRTC_ANDROID
705 webrtc::InitializeAndroidObjects();
706#endif
707 }
708
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 virtual void SetUp() {
710 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700711 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
712 nullptr, nullptr, nullptr);
713 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700714 pc_factory_for_test_ =
715 new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
716 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 }
718
719 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700720 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 }
722
deadbeef293e9262017-01-11 12:28:30 -0800723 // DTLS does not work in a loopback call, so is disabled for most of the
724 // tests in this file.
725 void CreatePeerConnectionWithoutDtls() {
726 FakeConstraints no_dtls_constraints;
727 no_dtls_constraints.AddMandatory(
728 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
729
730 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
731 &no_dtls_constraints);
732 }
733
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700735 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
736 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 }
738
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700739 void CreatePeerConnectionWithIceTransportsType(
740 PeerConnectionInterface::IceTransportsType type) {
741 PeerConnectionInterface::RTCConfiguration config;
742 config.type = type;
743 return CreatePeerConnection(config, nullptr);
744 }
745
746 void CreatePeerConnectionWithIceServer(const std::string& uri,
747 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800748 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700750 server.uri = uri;
751 server.password = password;
752 config.servers.push_back(server);
753 CreatePeerConnection(config, nullptr);
754 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700756 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
757 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700758 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800759 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
760 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000761
Henrik Boströmd79599d2016-06-01 13:58:50 +0200762 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000763 bool dtls;
764 if (FindConstraint(constraints,
765 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
766 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200767 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800768 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
769 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000770 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200771 pc_ = pc_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800772 config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200773 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 ASSERT_TRUE(pc_.get() != NULL);
775 observer_.SetPeerConnectionInterface(pc_.get());
776 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
777 }
778
deadbeef0a6c4ca2015-10-06 11:38:28 -0700779 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800780 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700781 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700782 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800783 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700784
zhihuang9763d562016-08-05 11:14:50 -0700785 rtc::scoped_refptr<PeerConnectionInterface> pc;
hbosd7973cc2016-05-27 06:08:53 -0700786 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
787 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800788 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700789 }
790
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700792 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800793 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
794 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
795 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800797 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798
deadbeef0a6c4ca2015-10-06 11:38:28 -0700799 CreatePeerConnectionExpectFail(kStunInvalidPort);
800 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
801 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700803 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
805 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800807 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800809 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800811 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 }
813
814 void ReleasePeerConnection() {
815 pc_ = NULL;
816 observer_.SetPeerConnectionInterface(NULL);
817 }
818
deadbeefab9b2d12015-10-14 11:33:11 -0700819 void AddVideoStream(const std::string& label) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700821 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700823 rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
zhihuang9763d562016-08-05 11:14:50 -0700825 rtc::scoped_refptr<VideoTrackInterface> video_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 pc_factory_->CreateVideoTrack(label + "v0", video_source));
827 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000828 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
830 observer_.renegotiation_needed_ = false;
831 }
832
833 void AddVoiceStream(const std::string& label) {
834 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700835 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700837 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 pc_factory_->CreateAudioTrack(label + "a0", NULL));
839 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000840 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
842 observer_.renegotiation_needed_ = false;
843 }
844
845 void AddAudioVideoStream(const std::string& stream_label,
846 const std::string& audio_track_label,
847 const std::string& video_track_label) {
848 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700849 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 pc_factory_->CreateLocalMediaStream(stream_label));
zhihuang9763d562016-08-05 11:14:50 -0700851 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 pc_factory_->CreateAudioTrack(
853 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
854 stream->AddTrack(audio_track.get());
zhihuang9763d562016-08-05 11:14:50 -0700855 rtc::scoped_refptr<VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -0700856 pc_factory_->CreateVideoTrack(
857 video_track_label,
858 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000860 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
862 observer_.renegotiation_needed_ = false;
863 }
864
kwibergd1fe2812016-04-27 06:47:29 -0700865 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700866 bool offer,
867 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000868 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
869 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 MockCreateSessionDescriptionObserver>());
871 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700872 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700874 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 }
876 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
kwiberg2bbff992016-03-16 11:03:04 -0700877 desc->reset(observer->release_desc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 return observer->result();
879 }
880
kwibergd1fe2812016-04-27 06:47:29 -0700881 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700882 MediaConstraintsInterface* constraints) {
883 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 }
885
kwibergd1fe2812016-04-27 06:47:29 -0700886 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700887 MediaConstraintsInterface* constraints) {
888 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 }
890
891 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000892 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
893 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 MockSetSessionDescriptionObserver>());
895 if (local) {
896 pc_->SetLocalDescription(observer, desc);
897 } else {
898 pc_->SetRemoteDescription(observer, desc);
899 }
zhihuang29ff8442016-07-27 11:07:25 -0700900 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
901 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
902 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 return observer->result();
904 }
905
906 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
907 return DoSetSessionDescription(desc, true);
908 }
909
910 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
911 return DoSetSessionDescription(desc, false);
912 }
913
914 // Calls PeerConnection::GetStats and check the return value.
915 // It does not verify the values in the StatReports since a RTCP packet might
916 // be required.
917 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000918 rtc::scoped_refptr<MockStatsObserver> observer(
919 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000920 if (!pc_->GetStats(
921 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 return false;
923 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
924 return observer->called();
925 }
926
927 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800928 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 // Create a local stream with audio&video tracks.
930 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
931 CreateOfferReceiveAnswer();
932 }
933
934 // Verify that RTP Header extensions has been negotiated for audio and video.
935 void VerifyRemoteRtpHeaderExtensions() {
936 const cricket::MediaContentDescription* desc =
937 cricket::GetFirstAudioContentDescription(
938 pc_->remote_description()->description());
939 ASSERT_TRUE(desc != NULL);
940 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
941
942 desc = cricket::GetFirstVideoContentDescription(
943 pc_->remote_description()->description());
944 ASSERT_TRUE(desc != NULL);
945 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
946 }
947
948 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700949 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700950 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 std::string sdp;
952 EXPECT_TRUE(offer->ToString(&sdp));
953 SessionDescriptionInterface* remote_offer =
954 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
955 sdp, NULL);
956 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
957 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
958 }
959
deadbeefab9b2d12015-10-14 11:33:11 -0700960 void CreateAndSetRemoteOffer(const std::string& sdp) {
961 SessionDescriptionInterface* remote_offer =
962 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
963 sdp, nullptr);
964 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
965 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
966 }
967
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700969 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700970 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971
972 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
973 // audio codec change, even if the parameter has nothing to do with
974 // receiving. Not all parameters are serialized to SDP.
975 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
976 // the SessionDescription, it is necessary to do that here to in order to
977 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
978 // https://code.google.com/p/webrtc/issues/detail?id=1356
979 std::string sdp;
980 EXPECT_TRUE(answer->ToString(&sdp));
981 SessionDescriptionInterface* new_answer =
982 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
983 sdp, NULL);
984 EXPECT_TRUE(DoSetLocalDescription(new_answer));
985 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
986 }
987
988 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700989 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700990 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 std::string sdp;
993 EXPECT_TRUE(answer->ToString(&sdp));
994 SessionDescriptionInterface* pr_answer =
995 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
996 sdp, NULL);
997 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
998 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
999 }
1000
1001 void CreateOfferReceiveAnswer() {
1002 CreateOfferAsLocalDescription();
1003 std::string sdp;
1004 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1005 CreateAnswerAsRemoteDescription(sdp);
1006 }
1007
1008 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001009 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001010 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1012 // audio codec change, even if the parameter has nothing to do with
1013 // receiving. Not all parameters are serialized to SDP.
1014 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1015 // the SessionDescription, it is necessary to do that here to in order to
1016 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1017 // https://code.google.com/p/webrtc/issues/detail?id=1356
1018 std::string sdp;
1019 EXPECT_TRUE(offer->ToString(&sdp));
1020 SessionDescriptionInterface* new_offer =
1021 webrtc::CreateSessionDescription(
1022 SessionDescriptionInterface::kOffer,
1023 sdp, NULL);
1024
1025 EXPECT_TRUE(DoSetLocalDescription(new_offer));
1026 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001027 // Wait for the ice_complete message, so that SDP will have candidates.
1028 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 }
1030
deadbeefab9b2d12015-10-14 11:33:11 -07001031 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1033 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001034 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 EXPECT_TRUE(DoSetRemoteDescription(answer));
1036 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1037 }
1038
deadbeefab9b2d12015-10-14 11:33:11 -07001039 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 webrtc::JsepSessionDescription* pr_answer =
1041 new webrtc::JsepSessionDescription(
1042 SessionDescriptionInterface::kPrAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001043 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
1045 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
1046 webrtc::JsepSessionDescription* answer =
1047 new webrtc::JsepSessionDescription(
1048 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001049 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 EXPECT_TRUE(DoSetRemoteDescription(answer));
1051 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1052 }
1053
1054 // Help function used for waiting until a the last signaled remote stream has
1055 // the same label as |stream_label|. In a few of the tests in this file we
1056 // answer with the same session description as we offer and thus we can
1057 // check if OnAddStream have been called with the same stream as we offer to
1058 // send.
1059 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
1060 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
1061 }
1062
1063 // Creates an offer and applies it as a local session description.
1064 // Creates an answer with the same SDP an the offer but removes all lines
1065 // that start with a:ssrc"
1066 void CreateOfferReceiveAnswerWithoutSsrc() {
1067 CreateOfferAsLocalDescription();
1068 std::string sdp;
1069 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1070 SetSsrcToZero(&sdp);
1071 CreateAnswerAsRemoteDescription(sdp);
1072 }
1073
deadbeefab9b2d12015-10-14 11:33:11 -07001074 // This function creates a MediaStream with label kStreams[0] and
1075 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1076 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001077 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001078 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001079 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001080 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1081 size_t number_of_video_tracks) {
1082 EXPECT_LE(number_of_audio_tracks, 2u);
1083 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001084
1085 reference_collection_ = StreamCollection::Create();
1086 std::string sdp_ms1 = std::string(kSdpStringInit);
1087
1088 std::string mediastream_label = kStreams[0];
1089
1090 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1091 webrtc::MediaStream::Create(mediastream_label));
1092 reference_collection_->AddStream(stream);
1093
1094 if (number_of_audio_tracks > 0) {
1095 sdp_ms1 += std::string(kSdpStringAudio);
1096 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1097 AddAudioTrack(kAudioTracks[0], stream);
1098 }
1099 if (number_of_audio_tracks > 1) {
1100 sdp_ms1 += kSdpStringMs1Audio1;
1101 AddAudioTrack(kAudioTracks[1], stream);
1102 }
1103
1104 if (number_of_video_tracks > 0) {
1105 sdp_ms1 += std::string(kSdpStringVideo);
1106 sdp_ms1 += std::string(kSdpStringMs1Video0);
1107 AddVideoTrack(kVideoTracks[0], stream);
1108 }
1109 if (number_of_video_tracks > 1) {
1110 sdp_ms1 += kSdpStringMs1Video1;
1111 AddVideoTrack(kVideoTracks[1], stream);
1112 }
1113
kwibergd1fe2812016-04-27 06:47:29 -07001114 return std::unique_ptr<SessionDescriptionInterface>(
kwiberg2bbff992016-03-16 11:03:04 -07001115 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1116 sdp_ms1, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001117 }
1118
1119 void AddAudioTrack(const std::string& track_id,
1120 MediaStreamInterface* stream) {
1121 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1122 webrtc::AudioTrack::Create(track_id, nullptr));
1123 ASSERT_TRUE(stream->AddTrack(audio_track));
1124 }
1125
1126 void AddVideoTrack(const std::string& track_id,
1127 MediaStreamInterface* stream) {
1128 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001129 webrtc::VideoTrack::Create(track_id,
1130 webrtc::FakeVideoTrackSource::Create()));
deadbeefab9b2d12015-10-14 11:33:11 -07001131 ASSERT_TRUE(stream->AddTrack(video_track));
1132 }
1133
kwibergfd8be342016-05-14 19:44:11 -07001134 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
deadbeef293e9262017-01-11 12:28:30 -08001135 CreatePeerConnectionWithoutDtls();
zhihuang8f65cdf2016-05-06 18:40:30 -07001136 AddVoiceStream(kStreamLabel1);
kwibergfd8be342016-05-14 19:44:11 -07001137 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001138 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1139 return offer;
1140 }
1141
kwibergfd8be342016-05-14 19:44:11 -07001142 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001143 CreateAnswerWithOneAudioStream() {
kwibergfd8be342016-05-14 19:44:11 -07001144 std::unique_ptr<SessionDescriptionInterface> offer =
zhihuang8f65cdf2016-05-06 18:40:30 -07001145 CreateOfferWithOneAudioStream();
1146 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergfd8be342016-05-14 19:44:11 -07001147 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001148 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1149 return answer;
1150 }
1151
1152 const std::string& GetFirstAudioStreamCname(
1153 const SessionDescriptionInterface* desc) {
1154 const cricket::ContentInfo* audio_content =
1155 cricket::GetFirstAudioContent(desc->description());
1156 const cricket::AudioContentDescription* audio_desc =
1157 static_cast<const cricket::AudioContentDescription*>(
1158 audio_content->description);
1159 return audio_desc->streams()[0].cname;
1160 }
1161
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001162 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001163 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001164 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1165 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1166 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001168 rtc::scoped_refptr<StreamCollection> reference_collection_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001169};
1170
zhihuang29ff8442016-07-27 11:07:25 -07001171// Test that no callbacks on the PeerConnectionObserver are called after the
1172// PeerConnection is closed.
1173TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) {
zhihuang9763d562016-08-05 11:14:50 -07001174 rtc::scoped_refptr<PeerConnectionInterface> pc(
zhihuang29ff8442016-07-27 11:07:25 -07001175 pc_factory_for_test_->CreatePeerConnection(
1176 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr,
1177 nullptr, &observer_));
1178 observer_.SetPeerConnectionInterface(pc.get());
1179 pc->Close();
1180
1181 // No callbacks is expected to be called.
zhihuang81c3a032016-11-17 12:06:24 -08001182 observer_.callback_triggered_ = false;
zhihuang29ff8442016-07-27 11:07:25 -07001183 std::vector<cricket::Candidate> candidates;
1184 pc_factory_for_test_->transport_controller->SignalGatheringState(
1185 cricket::IceGatheringState{});
1186 pc_factory_for_test_->transport_controller->SignalCandidatesGathered(
1187 "", candidates);
1188 pc_factory_for_test_->transport_controller->SignalConnectionState(
1189 cricket::IceConnectionState{});
1190 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved(
1191 candidates);
1192 pc_factory_for_test_->transport_controller->SignalReceiving(false);
zhihuang81c3a032016-11-17 12:06:24 -08001193 EXPECT_FALSE(observer_.callback_triggered_);
zhihuang29ff8442016-07-27 11:07:25 -07001194}
1195
zhihuang8f65cdf2016-05-06 18:40:30 -07001196// Generate different CNAMEs when PeerConnections are created.
1197// The CNAMEs are expected to be generated randomly. It is possible
1198// that the test fails, though the possibility is very low.
1199TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001200 std::unique_ptr<SessionDescriptionInterface> offer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001201 CreateOfferWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001202 std::unique_ptr<SessionDescriptionInterface> offer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001203 CreateOfferWithOneAudioStream();
1204 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1205 GetFirstAudioStreamCname(offer2.get()));
1206}
1207
1208TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001209 std::unique_ptr<SessionDescriptionInterface> answer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001210 CreateAnswerWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001211 std::unique_ptr<SessionDescriptionInterface> answer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001212 CreateAnswerWithOneAudioStream();
1213 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1214 GetFirstAudioStreamCname(answer2.get()));
1215}
1216
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217TEST_F(PeerConnectionInterfaceTest,
1218 CreatePeerConnectionWithDifferentConfigurations) {
1219 CreatePeerConnectionWithDifferentConfigurations();
1220}
1221
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001222TEST_F(PeerConnectionInterfaceTest,
1223 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1224 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1225 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1226 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1227 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1228 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1229 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1230 port_allocator_->candidate_filter());
1231 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1232 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1233}
1234
1235// Test that when a PeerConnection is created with a nonzero candidate pool
1236// size, the pooled PortAllocatorSession is created with all the attributes
1237// in the RTCConfiguration.
1238TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1239 PeerConnectionInterface::RTCConfiguration config;
1240 PeerConnectionInterface::IceServer server;
1241 server.uri = kStunAddressOnly;
1242 config.servers.push_back(server);
1243 config.type = PeerConnectionInterface::kRelay;
1244 config.disable_ipv6 = true;
1245 config.tcp_candidate_policy =
1246 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001247 config.candidate_network_policy =
1248 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001249 config.ice_candidate_pool_size = 1;
1250 CreatePeerConnection(config, nullptr);
1251
1252 const cricket::FakePortAllocatorSession* session =
1253 static_cast<const cricket::FakePortAllocatorSession*>(
1254 port_allocator_->GetPooledSession());
1255 ASSERT_NE(nullptr, session);
1256 EXPECT_EQ(1UL, session->stun_servers().size());
1257 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1258 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001259 EXPECT_LT(0U,
1260 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001261}
1262
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001263// Test that the PeerConnection initializes the port allocator passed into it,
1264// and on the correct thread.
1265TEST_F(PeerConnectionInterfaceTest,
1266 CreatePeerConnectionInitializesPortAllocator) {
1267 rtc::Thread network_thread;
1268 network_thread.Start();
1269 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1270 webrtc::CreatePeerConnectionFactory(
1271 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
1272 nullptr, nullptr, nullptr));
1273 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1274 new cricket::FakePortAllocator(&network_thread, nullptr));
1275 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1276 PeerConnectionInterface::RTCConfiguration config;
1277 rtc::scoped_refptr<PeerConnectionInterface> pc(
1278 pc_factory->CreatePeerConnection(
1279 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1280 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1281 // so all we have to do here is check that it's initialized.
1282 EXPECT_TRUE(raw_port_allocator->initialized());
1283}
1284
deadbeef46c73892016-11-16 19:42:04 -08001285// Check that GetConfiguration returns the configuration the PeerConnection was
1286// constructed with, before SetConfiguration is called.
1287TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1288 PeerConnectionInterface::RTCConfiguration config;
1289 config.type = PeerConnectionInterface::kRelay;
1290 CreatePeerConnection(config, nullptr);
1291
1292 PeerConnectionInterface::RTCConfiguration returned_config =
1293 pc_->GetConfiguration();
1294 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1295}
1296
1297// Check that GetConfiguration returns the last configuration passed into
1298// SetConfiguration.
1299TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1300 CreatePeerConnection();
1301
1302 PeerConnectionInterface::RTCConfiguration config;
1303 config.type = PeerConnectionInterface::kRelay;
1304 EXPECT_TRUE(pc_->SetConfiguration(config));
1305
1306 PeerConnectionInterface::RTCConfiguration returned_config =
1307 pc_->GetConfiguration();
1308 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1309}
1310
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311TEST_F(PeerConnectionInterfaceTest, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001312 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001313 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 AddVoiceStream(kStreamLabel2);
1315 ASSERT_EQ(2u, pc_->local_streams()->count());
1316
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001317 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001318 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
zhihuang9763d562016-08-05 11:14:50 -07001320 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1321 pc_factory_->CreateAudioTrack(kStreamLabel3,
1322 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001324 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001325 EXPECT_EQ(3u, pc_->local_streams()->count());
1326
1327 // Remove the third stream.
1328 pc_->RemoveStream(pc_->local_streams()->at(2));
1329 EXPECT_EQ(2u, pc_->local_streams()->count());
1330
1331 // Remove the second stream.
1332 pc_->RemoveStream(pc_->local_streams()->at(1));
1333 EXPECT_EQ(1u, pc_->local_streams()->count());
1334
1335 // Remove the first stream.
1336 pc_->RemoveStream(pc_->local_streams()->at(0));
1337 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338}
1339
deadbeefab9b2d12015-10-14 11:33:11 -07001340// Test that the created offer includes streams we added.
1341TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001342 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001343 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001344 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001345 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001346
1347 const cricket::ContentInfo* audio_content =
1348 cricket::GetFirstAudioContent(offer->description());
1349 const cricket::AudioContentDescription* audio_desc =
1350 static_cast<const cricket::AudioContentDescription*>(
1351 audio_content->description);
1352 EXPECT_TRUE(
1353 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1354
1355 const cricket::ContentInfo* video_content =
1356 cricket::GetFirstVideoContent(offer->description());
1357 const cricket::VideoContentDescription* video_desc =
1358 static_cast<const cricket::VideoContentDescription*>(
1359 video_content->description);
1360 EXPECT_TRUE(
1361 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1362
1363 // Add another stream and ensure the offer includes both the old and new
1364 // streams.
1365 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001366 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001367
1368 audio_content = cricket::GetFirstAudioContent(offer->description());
1369 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1370 audio_content->description);
1371 EXPECT_TRUE(
1372 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1373 EXPECT_TRUE(
1374 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1375
1376 video_content = cricket::GetFirstVideoContent(offer->description());
1377 video_desc = static_cast<const cricket::VideoContentDescription*>(
1378 video_content->description);
1379 EXPECT_TRUE(
1380 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1381 EXPECT_TRUE(
1382 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1383}
1384
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001386 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001387 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 ASSERT_EQ(1u, pc_->local_streams()->count());
1389 pc_->RemoveStream(pc_->local_streams()->at(0));
1390 EXPECT_EQ(0u, pc_->local_streams()->count());
1391}
1392
deadbeefe1f9d832016-01-14 15:35:42 -08001393// Test for AddTrack and RemoveTrack methods.
1394// Tests that the created offer includes tracks we added,
1395// and that the RtpSenders are created correctly.
1396// Also tests that RemoveTrack removes the tracks from subsequent offers.
1397TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001398 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001399 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001400 rtc::scoped_refptr<MediaStreamInterface> stream(
deadbeefe1f9d832016-01-14 15:35:42 -08001401 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1402 std::vector<MediaStreamInterface*> stream_list;
1403 stream_list.push_back(stream.get());
zhihuang9763d562016-08-05 11:14:50 -07001404 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001405 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001406 rtc::scoped_refptr<VideoTrackInterface> video_track(
1407 pc_factory_->CreateVideoTrack(
1408 "video_track",
1409 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefe1f9d832016-01-14 15:35:42 -08001410 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1411 auto video_sender = pc_->AddTrack(video_track, stream_list);
deadbeefa601f5c2016-06-06 14:27:39 -07001412 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1413 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001414 EXPECT_EQ("audio_track", audio_sender->id());
1415 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001416 EXPECT_EQ(1UL, video_sender->stream_ids().size());
1417 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001418 EXPECT_EQ("video_track", video_sender->id());
1419 EXPECT_EQ(video_track, video_sender->track());
1420
1421 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001422 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001423 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001424
1425 const cricket::ContentInfo* audio_content =
1426 cricket::GetFirstAudioContent(offer->description());
1427 const cricket::AudioContentDescription* audio_desc =
1428 static_cast<const cricket::AudioContentDescription*>(
1429 audio_content->description);
1430 EXPECT_TRUE(
1431 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1432
1433 const cricket::ContentInfo* video_content =
1434 cricket::GetFirstVideoContent(offer->description());
1435 const cricket::VideoContentDescription* video_desc =
1436 static_cast<const cricket::VideoContentDescription*>(
1437 video_content->description);
1438 EXPECT_TRUE(
1439 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1440
1441 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1442
1443 // Now try removing the tracks.
1444 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1445 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1446
1447 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001448 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001449
1450 audio_content = cricket::GetFirstAudioContent(offer->description());
1451 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1452 audio_content->description);
1453 EXPECT_FALSE(
1454 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1455
1456 video_content = cricket::GetFirstVideoContent(offer->description());
1457 video_desc = static_cast<const cricket::VideoContentDescription*>(
1458 video_content->description);
1459 EXPECT_FALSE(
1460 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1461
1462 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1463
1464 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1465 // should return false.
1466 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1467 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1468}
1469
1470// Test creating senders without a stream specified,
1471// expecting a random stream ID to be generated.
1472TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001473 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001474 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001475 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001476 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001477 rtc::scoped_refptr<VideoTrackInterface> video_track(
1478 pc_factory_->CreateVideoTrack(
1479 "video_track",
1480 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefe1f9d832016-01-14 15:35:42 -08001481 auto audio_sender =
1482 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1483 auto video_sender =
1484 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1485 EXPECT_EQ("audio_track", audio_sender->id());
1486 EXPECT_EQ(audio_track, audio_sender->track());
1487 EXPECT_EQ("video_track", video_sender->id());
1488 EXPECT_EQ(video_track, video_sender->track());
1489 // If the ID is truly a random GUID, it should be infinitely unlikely they
1490 // will be the same.
deadbeefa601f5c2016-06-06 14:27:39 -07001491 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
deadbeefe1f9d832016-01-14 15:35:42 -08001492}
1493
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1495 InitiateCall();
1496 WaitAndVerifyOnAddStream(kStreamLabel1);
1497 VerifyRemoteRtpHeaderExtensions();
1498}
1499
1500TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001501 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001502 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 CreateOfferAsLocalDescription();
1504 std::string offer;
1505 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1506 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1507 WaitAndVerifyOnAddStream(kStreamLabel1);
1508}
1509
1510TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001511 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001512 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513
1514 CreateOfferAsRemoteDescription();
1515 CreateAnswerAsLocalDescription();
1516
1517 WaitAndVerifyOnAddStream(kStreamLabel1);
1518}
1519
1520TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001521 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001522 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523
1524 CreateOfferAsRemoteDescription();
1525 CreatePrAnswerAsLocalDescription();
1526 CreateAnswerAsLocalDescription();
1527
1528 WaitAndVerifyOnAddStream(kStreamLabel1);
1529}
1530
1531TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1532 InitiateCall();
1533 ASSERT_EQ(1u, pc_->remote_streams()->count());
1534 pc_->RemoveStream(pc_->local_streams()->at(0));
1535 CreateOfferReceiveAnswer();
1536 EXPECT_EQ(0u, pc_->remote_streams()->count());
deadbeefab9b2d12015-10-14 11:33:11 -07001537 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 CreateOfferReceiveAnswer();
1539}
1540
1541// Tests that after negotiating an audio only call, the respondent can perform a
1542// renegotiation that removes the audio stream.
1543TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001544 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 AddVoiceStream(kStreamLabel1);
1546 CreateOfferAsRemoteDescription();
1547 CreateAnswerAsLocalDescription();
1548
1549 ASSERT_EQ(1u, pc_->remote_streams()->count());
1550 pc_->RemoveStream(pc_->local_streams()->at(0));
1551 CreateOfferReceiveAnswer();
1552 EXPECT_EQ(0u, pc_->remote_streams()->count());
1553}
1554
1555// Test that candidates are generated and that we can parse our own candidates.
1556TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001557 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558
1559 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1560 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001561 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefab9b2d12015-10-14 11:33:11 -07001562 AddVideoStream(kStreamLabel1);
deadbeefc80741f2015-10-22 13:14:45 -07001563 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001564 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565
1566 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001567 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001568 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001569 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570
1571 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1572 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1573
1574 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1575}
1576
deadbeefab9b2d12015-10-14 11:33:11 -07001577// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578// not unique.
1579TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001580 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001582 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001583 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001584 EXPECT_TRUE(offer);
1585 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586
1587 // Create a local stream with audio&video tracks having same label.
1588 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1589
1590 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001591 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592
1593 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001594 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001595 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596}
1597
1598// Test that we will get different SSRCs for each tracks in the offer and answer
1599// we created.
1600TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001601 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 // Create a local stream with audio&video tracks having different labels.
1603 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1604
1605 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001606 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001607 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 int audio_ssrc = 0;
1609 int video_ssrc = 0;
1610 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1611 &audio_ssrc));
1612 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1613 &video_ssrc));
1614 EXPECT_NE(audio_ssrc, video_ssrc);
1615
1616 // Test CreateAnswer
1617 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergd1fe2812016-04-27 06:47:29 -07001618 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001619 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 audio_ssrc = 0;
1621 video_ssrc = 0;
1622 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1623 &audio_ssrc));
1624 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1625 &video_ssrc));
1626 EXPECT_NE(audio_ssrc, video_ssrc);
1627}
1628
deadbeefeb459812015-12-15 19:24:43 -08001629// Test that it's possible to call AddTrack on a MediaStream after adding
1630// the stream to a PeerConnection.
1631// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1632TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001633 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001634 // Create audio stream and add to PeerConnection.
1635 AddVoiceStream(kStreamLabel1);
1636 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1637
1638 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001639 rtc::scoped_refptr<VideoTrackInterface> video_track(
1640 pc_factory_->CreateVideoTrack(
1641 "video_label",
1642 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
deadbeefeb459812015-12-15 19:24:43 -08001643 stream->AddTrack(video_track.get());
1644
kwibergd1fe2812016-04-27 06:47:29 -07001645 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001646 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001647
1648 const cricket::MediaContentDescription* video_desc =
1649 cricket::GetFirstVideoContentDescription(offer->description());
1650 EXPECT_TRUE(video_desc != nullptr);
1651}
1652
1653// Test that it's possible to call RemoveTrack on a MediaStream after adding
1654// the stream to a PeerConnection.
1655// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1656TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001657 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001658 // Create audio/video stream and add to PeerConnection.
1659 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1660 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1661
1662 // Remove the video track.
1663 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1664
kwibergd1fe2812016-04-27 06:47:29 -07001665 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001666 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001667
1668 const cricket::MediaContentDescription* video_desc =
1669 cricket::GetFirstVideoContentDescription(offer->description());
1670 EXPECT_TRUE(video_desc == nullptr);
1671}
1672
deadbeefbd7d8f72015-12-18 16:58:44 -08001673// Test creating a sender with a stream ID, and ensure the ID is populated
1674// in the offer.
1675TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001676 CreatePeerConnectionWithoutDtls();
deadbeefbd7d8f72015-12-18 16:58:44 -08001677 pc_->CreateSender("video", kStreamLabel1);
1678
kwibergd1fe2812016-04-27 06:47:29 -07001679 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001680 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001681
1682 const cricket::MediaContentDescription* video_desc =
1683 cricket::GetFirstVideoContentDescription(offer->description());
1684 ASSERT_TRUE(video_desc != nullptr);
1685 ASSERT_EQ(1u, video_desc->streams().size());
1686 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1687}
1688
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689// Test that we can specify a certain track that we want statistics about.
1690TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1691 InitiateCall();
1692 ASSERT_LT(0u, pc_->remote_streams()->count());
1693 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001694 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1696 EXPECT_TRUE(DoGetStats(remote_audio));
1697
1698 // Remove the stream. Since we are sending to our selves the local
1699 // and the remote stream is the same.
1700 pc_->RemoveStream(pc_->local_streams()->at(0));
1701 // Do a re-negotiation.
1702 CreateOfferReceiveAnswer();
1703
1704 ASSERT_EQ(0u, pc_->remote_streams()->count());
1705
1706 // Test that we still can get statistics for the old track. Even if it is not
1707 // sent any longer.
1708 EXPECT_TRUE(DoGetStats(remote_audio));
1709}
1710
1711// Test that we can get stats on a video track.
1712TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1713 InitiateCall();
1714 ASSERT_LT(0u, pc_->remote_streams()->count());
1715 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001716 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1718 EXPECT_TRUE(DoGetStats(remote_video));
1719}
1720
1721// Test that we don't get statistics for an invalid track.
zhihuange9e94c32016-11-04 11:38:15 -07001722TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001724 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 pc_factory_->CreateAudioTrack("unknown track", NULL));
1726 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1727}
1728
1729// This test setup two RTP data channels in loop back.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 FakeConstraints constraints;
1732 constraints.SetAllowRtpDataChannels();
1733 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001734 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001736 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 pc_->CreateDataChannel("test2", NULL);
1738 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001739 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001741 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 new MockDataChannelObserver(data2));
1743
1744 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1745 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1746 std::string data_to_send1 = "testing testing";
1747 std::string data_to_send2 = "testing something else";
1748 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1749
1750 CreateOfferReceiveAnswer();
1751 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1752 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1753
1754 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1755 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1756 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1757 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1758
1759 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1760 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1761
1762 data1->Close();
1763 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1764 CreateOfferReceiveAnswer();
1765 EXPECT_FALSE(observer1->IsOpen());
1766 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1767 EXPECT_TRUE(observer2->IsOpen());
1768
1769 data_to_send2 = "testing something else again";
1770 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1771
1772 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1773}
1774
1775// This test verifies that sendnig binary data over RTP data channels should
1776// fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 FakeConstraints constraints;
1779 constraints.SetAllowRtpDataChannels();
1780 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001781 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001783 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 pc_->CreateDataChannel("test2", NULL);
1785 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001786 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001788 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 new MockDataChannelObserver(data2));
1790
1791 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1792 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1793
1794 CreateOfferReceiveAnswer();
1795 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1796 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1797
1798 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1799 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1800
jbaucheec21bd2016-03-20 06:15:43 -07001801 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1803}
1804
1805// This test setup a RTP data channels in loop back and test that a channel is
1806// opened even if the remote end answer with a zero SSRC.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 FakeConstraints constraints;
1809 constraints.SetAllowRtpDataChannels();
1810 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001811 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001813 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 new MockDataChannelObserver(data1));
1815
1816 CreateOfferReceiveAnswerWithoutSsrc();
1817
1818 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1819
1820 data1->Close();
1821 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1822 CreateOfferReceiveAnswerWithoutSsrc();
1823 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1824 EXPECT_FALSE(observer1->IsOpen());
1825}
1826
1827// This test that if a data channel is added in an answer a receive only channel
1828// channel is created.
1829TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1830 FakeConstraints constraints;
1831 constraints.SetAllowRtpDataChannels();
1832 CreatePeerConnection(&constraints);
1833
1834 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07001835 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 pc_->CreateDataChannel(offer_label, NULL);
1837
1838 CreateOfferAsLocalDescription();
1839
1840 // Replace the data channel label in the offer and apply it as an answer.
1841 std::string receive_label = "answer_channel";
1842 std::string sdp;
1843 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001844 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 receive_label.c_str(), receive_label.length(),
1846 &sdp);
1847 CreateAnswerAsRemoteDescription(sdp);
1848
1849 // Verify that a new incoming data channel has been created and that
1850 // it is open but can't we written to.
1851 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1852 DataChannelInterface* received_channel = observer_.last_datachannel_;
1853 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1854 EXPECT_EQ(receive_label, received_channel->label());
1855 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1856
1857 // Verify that the channel we initially offered has been rejected.
1858 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1859
1860 // Do another offer / answer exchange and verify that the data channel is
1861 // opened.
1862 CreateOfferReceiveAnswer();
1863 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1864 kTimeout);
1865}
1866
1867// This test that no data channel is returned if a reliable channel is
1868// requested.
1869// TODO(perkj): Remove this test once reliable channels are implemented.
1870TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1871 FakeConstraints constraints;
1872 constraints.SetAllowRtpDataChannels();
1873 CreatePeerConnection(&constraints);
1874
1875 std::string label = "test";
1876 webrtc::DataChannelInit config;
1877 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07001878 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 pc_->CreateDataChannel(label, &config);
1880 EXPECT_TRUE(channel == NULL);
1881}
1882
deadbeefab9b2d12015-10-14 11:33:11 -07001883// Verifies that duplicated label is not allowed for RTP data channel.
1884TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1885 FakeConstraints constraints;
1886 constraints.SetAllowRtpDataChannels();
1887 CreatePeerConnection(&constraints);
1888
1889 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001890 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001891 pc_->CreateDataChannel(label, nullptr);
1892 EXPECT_NE(channel, nullptr);
1893
zhihuang9763d562016-08-05 11:14:50 -07001894 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001895 pc_->CreateDataChannel(label, nullptr);
1896 EXPECT_EQ(dup_channel, nullptr);
1897}
1898
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899// This tests that a SCTP data channel is returned using different
1900// DataChannelInit configurations.
1901TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1902 FakeConstraints constraints;
1903 constraints.SetAllowDtlsSctpDataChannels();
1904 CreatePeerConnection(&constraints);
1905
1906 webrtc::DataChannelInit config;
1907
zhihuang9763d562016-08-05 11:14:50 -07001908 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 pc_->CreateDataChannel("1", &config);
1910 EXPECT_TRUE(channel != NULL);
1911 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001912 EXPECT_TRUE(observer_.renegotiation_needed_);
1913 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914
1915 config.ordered = false;
1916 channel = pc_->CreateDataChannel("2", &config);
1917 EXPECT_TRUE(channel != NULL);
1918 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001919 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920
1921 config.ordered = true;
1922 config.maxRetransmits = 0;
1923 channel = pc_->CreateDataChannel("3", &config);
1924 EXPECT_TRUE(channel != NULL);
1925 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001926 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927
1928 config.maxRetransmits = -1;
1929 config.maxRetransmitTime = 0;
1930 channel = pc_->CreateDataChannel("4", &config);
1931 EXPECT_TRUE(channel != NULL);
1932 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001933 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934}
1935
1936// This tests that no data channel is returned if both maxRetransmits and
1937// maxRetransmitTime are set for SCTP data channels.
1938TEST_F(PeerConnectionInterfaceTest,
1939 CreateSctpDataChannelShouldFailForInvalidConfig) {
1940 FakeConstraints constraints;
1941 constraints.SetAllowDtlsSctpDataChannels();
1942 CreatePeerConnection(&constraints);
1943
1944 std::string label = "test";
1945 webrtc::DataChannelInit config;
1946 config.maxRetransmits = 0;
1947 config.maxRetransmitTime = 0;
1948
zhihuang9763d562016-08-05 11:14:50 -07001949 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 pc_->CreateDataChannel(label, &config);
1951 EXPECT_TRUE(channel == NULL);
1952}
1953
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954// The test verifies that creating a SCTP data channel with an id already in use
1955// or out of range should fail.
1956TEST_F(PeerConnectionInterfaceTest,
1957 CreateSctpDataChannelWithInvalidIdShouldFail) {
1958 FakeConstraints constraints;
1959 constraints.SetAllowDtlsSctpDataChannels();
1960 CreatePeerConnection(&constraints);
1961
1962 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07001963 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001965 config.id = 1;
1966 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 EXPECT_TRUE(channel != NULL);
1968 EXPECT_EQ(1, channel->id());
1969
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 channel = pc_->CreateDataChannel("x", &config);
1971 EXPECT_TRUE(channel == NULL);
1972
1973 config.id = cricket::kMaxSctpSid;
1974 channel = pc_->CreateDataChannel("max", &config);
1975 EXPECT_TRUE(channel != NULL);
1976 EXPECT_EQ(config.id, channel->id());
1977
1978 config.id = cricket::kMaxSctpSid + 1;
1979 channel = pc_->CreateDataChannel("x", &config);
1980 EXPECT_TRUE(channel == NULL);
1981}
1982
deadbeefab9b2d12015-10-14 11:33:11 -07001983// Verifies that duplicated label is allowed for SCTP data channel.
1984TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
1985 FakeConstraints constraints;
1986 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1987 true);
1988 CreatePeerConnection(&constraints);
1989
1990 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001991 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001992 pc_->CreateDataChannel(label, nullptr);
1993 EXPECT_NE(channel, nullptr);
1994
zhihuang9763d562016-08-05 11:14:50 -07001995 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001996 pc_->CreateDataChannel(label, nullptr);
1997 EXPECT_NE(dup_channel, nullptr);
1998}
1999
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002000// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2001// DataChannel.
2002TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
2003 FakeConstraints constraints;
2004 constraints.SetAllowRtpDataChannels();
2005 CreatePeerConnection(&constraints);
2006
zhihuang9763d562016-08-05 11:14:50 -07002007 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002008 pc_->CreateDataChannel("test1", NULL);
2009 EXPECT_TRUE(observer_.renegotiation_needed_);
2010 observer_.renegotiation_needed_ = false;
2011
zhihuang9763d562016-08-05 11:14:50 -07002012 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002013 pc_->CreateDataChannel("test2", NULL);
2014 EXPECT_TRUE(observer_.renegotiation_needed_);
2015}
2016
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017// This test that a data channel closes when a PeerConnection is deleted/closed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 FakeConstraints constraints;
2020 constraints.SetAllowRtpDataChannels();
2021 CreatePeerConnection(&constraints);
2022
zhihuang9763d562016-08-05 11:14:50 -07002023 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002025 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 pc_->CreateDataChannel("test2", NULL);
2027 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002028 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002030 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 new MockDataChannelObserver(data2));
2032
2033 CreateOfferReceiveAnswer();
2034 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2035 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2036
2037 ReleasePeerConnection();
2038 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2039 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2040}
2041
2042// This test that data channels can be rejected in an answer.
2043TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
2044 FakeConstraints constraints;
2045 constraints.SetAllowRtpDataChannels();
2046 CreatePeerConnection(&constraints);
2047
zhihuang9763d562016-08-05 11:14:50 -07002048 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 pc_->CreateDataChannel("offer_channel", NULL));
2050
2051 CreateOfferAsLocalDescription();
2052
2053 // Create an answer where the m-line for data channels are rejected.
2054 std::string sdp;
2055 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2056 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
2057 SessionDescriptionInterface::kAnswer);
2058 EXPECT_TRUE(answer->Initialize(sdp, NULL));
2059 cricket::ContentInfo* data_info =
2060 answer->description()->GetContentByName("data");
2061 data_info->rejected = true;
2062
2063 DoSetRemoteDescription(answer);
2064 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2065}
2066
2067// Test that we can create a session description from an SDP string from
2068// FireFox, use it as a remote session description, generate an answer and use
2069// the answer as a local description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002070TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071 FakeConstraints constraints;
2072 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2073 true);
2074 CreatePeerConnection(&constraints);
2075 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2076 SessionDescriptionInterface* desc =
2077 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002078 webrtc::kFireFoxSdpOffer, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2080 CreateAnswerAsLocalDescription();
2081 ASSERT_TRUE(pc_->local_description() != NULL);
2082 ASSERT_TRUE(pc_->remote_description() != NULL);
2083
2084 const cricket::ContentInfo* content =
2085 cricket::GetFirstAudioContent(pc_->local_description()->description());
2086 ASSERT_TRUE(content != NULL);
2087 EXPECT_FALSE(content->rejected);
2088
2089 content =
2090 cricket::GetFirstVideoContent(pc_->local_description()->description());
2091 ASSERT_TRUE(content != NULL);
2092 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002093#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 content =
2095 cricket::GetFirstDataContent(pc_->local_description()->description());
2096 ASSERT_TRUE(content != NULL);
2097 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002098#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099}
2100
deadbeef8662f942017-01-20 21:20:51 -08002101// Test that an offer can be received which offers DTLS with SDES fallback.
2102// Regression test for issue:
2103// https://bugs.chromium.org/p/webrtc/issues/detail?id=6972
2104TEST_F(PeerConnectionInterfaceTest, ReceiveDtlsSdesFallbackOffer) {
2105 FakeConstraints constraints;
2106 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2107 true);
2108 CreatePeerConnection(&constraints);
2109 // Wait for fake certificate to be generated. Previously, this is what caused
2110 // the "a=crypto" lines to be rejected.
2111 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2112 ASSERT_NE(nullptr, fake_certificate_generator_);
2113 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2114 kTimeout);
2115 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
2116 SessionDescriptionInterface::kOffer, kDtlsSdesFallbackSdp, nullptr);
2117 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2118 CreateAnswerAsLocalDescription();
2119}
2120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121// Test that we can create an audio only offer and receive an answer with a
2122// limited set of audio codecs and receive an updated offer with more audio
2123// codecs, where the added codecs are not supported.
2124TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002125 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 AddVoiceStream("audio_label");
2127 CreateOfferAsLocalDescription();
2128
2129 SessionDescriptionInterface* answer =
2130 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
jbauchfabe2c92015-07-16 13:43:14 -07002131 webrtc::kAudioSdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 EXPECT_TRUE(DoSetSessionDescription(answer, false));
2133
2134 SessionDescriptionInterface* updated_offer =
2135 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002136 webrtc::kAudioSdpWithUnsupportedCodecs,
2137 nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
2139 CreateAnswerAsLocalDescription();
2140}
2141
deadbeefc80741f2015-10-22 13:14:45 -07002142// Test that if we're receiving (but not sending) a track, subsequent offers
2143// will have m-lines with a=recvonly.
2144TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2145 FakeConstraints constraints;
2146 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2147 true);
2148 CreatePeerConnection(&constraints);
2149 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2150 CreateAnswerAsLocalDescription();
2151
2152 // At this point we should be receiving stream 1, but not sending anything.
2153 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002154 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002155 DoCreateOffer(&offer, nullptr);
2156
2157 const cricket::ContentInfo* video_content =
2158 cricket::GetFirstVideoContent(offer->description());
2159 const cricket::VideoContentDescription* video_desc =
2160 static_cast<const cricket::VideoContentDescription*>(
2161 video_content->description);
2162 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
2163
2164 const cricket::ContentInfo* audio_content =
2165 cricket::GetFirstAudioContent(offer->description());
2166 const cricket::AudioContentDescription* audio_desc =
2167 static_cast<const cricket::AudioContentDescription*>(
2168 audio_content->description);
2169 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
2170}
2171
2172// Test that if we're receiving (but not sending) a track, and the
2173// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2174// false, the generated m-lines will be a=inactive.
2175TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2176 FakeConstraints constraints;
2177 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2178 true);
2179 CreatePeerConnection(&constraints);
2180 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2181 CreateAnswerAsLocalDescription();
2182
2183 // At this point we should be receiving stream 1, but not sending anything.
2184 // A new offer would be recvonly, but we'll set the "no receive" constraints
2185 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002186 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002187 FakeConstraints offer_constraints;
2188 offer_constraints.AddMandatory(
2189 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2190 offer_constraints.AddMandatory(
2191 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2192 DoCreateOffer(&offer, &offer_constraints);
2193
2194 const cricket::ContentInfo* video_content =
2195 cricket::GetFirstVideoContent(offer->description());
2196 const cricket::VideoContentDescription* video_desc =
2197 static_cast<const cricket::VideoContentDescription*>(
2198 video_content->description);
2199 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
2200
2201 const cricket::ContentInfo* audio_content =
2202 cricket::GetFirstAudioContent(offer->description());
2203 const cricket::AudioContentDescription* audio_desc =
2204 static_cast<const cricket::AudioContentDescription*>(
2205 audio_content->description);
2206 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
2207}
2208
deadbeef653b8e02015-11-11 12:55:10 -08002209// Test that we can use SetConfiguration to change the ICE servers of the
2210// PortAllocator.
2211TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2212 CreatePeerConnection();
2213
2214 PeerConnectionInterface::RTCConfiguration config;
2215 PeerConnectionInterface::IceServer server;
2216 server.uri = "stun:test_hostname";
2217 config.servers.push_back(server);
2218 EXPECT_TRUE(pc_->SetConfiguration(config));
2219
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002220 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2221 EXPECT_EQ("test_hostname",
2222 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002223}
2224
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002225TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2226 CreatePeerConnection();
2227 PeerConnectionInterface::RTCConfiguration config;
2228 config.type = PeerConnectionInterface::kRelay;
2229 EXPECT_TRUE(pc_->SetConfiguration(config));
2230 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2231}
2232
deadbeef293e9262017-01-11 12:28:30 -08002233TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
2234 PeerConnectionInterface::RTCConfiguration config;
2235 config.prune_turn_ports = false;
2236 CreatePeerConnection(config, nullptr);
2237 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2238
2239 config.prune_turn_ports = true;
2240 EXPECT_TRUE(pc_->SetConfiguration(config));
2241 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2242}
2243
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002244// Test that when SetConfiguration changes both the pool size and other
2245// attributes, the pooled session is created with the updated attributes.
2246TEST_F(PeerConnectionInterfaceTest,
2247 SetConfigurationCreatesPooledSessionCorrectly) {
2248 CreatePeerConnection();
2249 PeerConnectionInterface::RTCConfiguration config;
2250 config.ice_candidate_pool_size = 1;
2251 PeerConnectionInterface::IceServer server;
2252 server.uri = kStunAddressOnly;
2253 config.servers.push_back(server);
2254 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002255 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002256
2257 const cricket::FakePortAllocatorSession* session =
2258 static_cast<const cricket::FakePortAllocatorSession*>(
2259 port_allocator_->GetPooledSession());
2260 ASSERT_NE(nullptr, session);
2261 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002262}
2263
deadbeef293e9262017-01-11 12:28:30 -08002264// Test that after SetLocalDescription, changing the pool size is not allowed,
2265// and an invalid modification error is returned.
deadbeef6de92f92016-12-12 18:49:32 -08002266TEST_F(PeerConnectionInterfaceTest,
2267 CantChangePoolSizeAfterSetLocalDescription) {
2268 CreatePeerConnection();
2269 // Start by setting a size of 1.
2270 PeerConnectionInterface::RTCConfiguration config;
2271 config.ice_candidate_pool_size = 1;
2272 EXPECT_TRUE(pc_->SetConfiguration(config));
2273
2274 // Set remote offer; can still change pool size at this point.
2275 CreateOfferAsRemoteDescription();
2276 config.ice_candidate_pool_size = 2;
2277 EXPECT_TRUE(pc_->SetConfiguration(config));
2278
2279 // Set local answer; now it's too late.
2280 CreateAnswerAsLocalDescription();
2281 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002282 RTCError error;
2283 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2284 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2285}
2286
2287// Test that SetConfiguration returns an invalid modification error if
2288// modifying a field in the configuration that isn't allowed to be modified.
2289TEST_F(PeerConnectionInterfaceTest,
2290 SetConfigurationReturnsInvalidModificationError) {
2291 PeerConnectionInterface::RTCConfiguration config;
2292 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2293 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2294 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2295 CreatePeerConnection(config, nullptr);
2296
2297 PeerConnectionInterface::RTCConfiguration modified_config = config;
2298 modified_config.bundle_policy =
2299 PeerConnectionInterface::kBundlePolicyMaxBundle;
2300 RTCError error;
2301 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2302 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2303
2304 modified_config = config;
2305 modified_config.rtcp_mux_policy =
2306 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2307 error.set_type(RTCErrorType::NONE);
2308 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2309 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2310
2311 modified_config = config;
2312 modified_config.continual_gathering_policy =
2313 PeerConnectionInterface::GATHER_CONTINUALLY;
2314 error.set_type(RTCErrorType::NONE);
2315 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2316 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2317}
2318
2319// Test that SetConfiguration returns a range error if the candidate pool size
2320// is negative or larger than allowed by the spec.
2321TEST_F(PeerConnectionInterfaceTest,
2322 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2323 PeerConnectionInterface::RTCConfiguration config;
2324 CreatePeerConnection(config, nullptr);
2325
2326 config.ice_candidate_pool_size = -1;
2327 RTCError error;
2328 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2329 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2330
2331 config.ice_candidate_pool_size = INT_MAX;
2332 error.set_type(RTCErrorType::NONE);
2333 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2334 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2335}
2336
2337// Test that SetConfiguration returns a syntax error if parsing an ICE server
2338// URL failed.
2339TEST_F(PeerConnectionInterfaceTest,
2340 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2341 PeerConnectionInterface::RTCConfiguration config;
2342 CreatePeerConnection(config, nullptr);
2343
2344 PeerConnectionInterface::IceServer bad_server;
2345 bad_server.uri = "stunn:www.example.com";
2346 config.servers.push_back(bad_server);
2347 RTCError error;
2348 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2349 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2350}
2351
2352// Test that SetConfiguration returns an invalid parameter error if a TURN
2353// IceServer is missing a username or password.
2354TEST_F(PeerConnectionInterfaceTest,
2355 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2356 PeerConnectionInterface::RTCConfiguration config;
2357 CreatePeerConnection(config, nullptr);
2358
2359 PeerConnectionInterface::IceServer bad_server;
2360 bad_server.uri = "turn:www.example.com";
2361 // Missing password.
2362 bad_server.username = "foo";
2363 config.servers.push_back(bad_server);
2364 RTCError error;
2365 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2366 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002367}
2368
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369// Test that PeerConnection::Close changes the states to closed and all remote
2370// tracks change state to ended.
2371TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2372 // Initialize a PeerConnection and negotiate local and remote session
2373 // description.
2374 InitiateCall();
2375 ASSERT_EQ(1u, pc_->local_streams()->count());
2376 ASSERT_EQ(1u, pc_->remote_streams()->count());
2377
2378 pc_->Close();
2379
2380 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2381 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2382 pc_->ice_connection_state());
2383 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2384 pc_->ice_gathering_state());
2385
2386 EXPECT_EQ(1u, pc_->local_streams()->count());
2387 EXPECT_EQ(1u, pc_->remote_streams()->count());
2388
zhihuang9763d562016-08-05 11:14:50 -07002389 rtc::scoped_refptr<MediaStreamInterface> remote_stream =
2390 pc_->remote_streams()->at(0);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002391 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002392 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002393 remote_stream->GetAudioTracks()[0]->state(), kTimeout);
2394 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2395 remote_stream->GetVideoTracks()[0]->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396}
2397
2398// Test that PeerConnection methods fails gracefully after
2399// PeerConnection::Close has been called.
2400TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002401 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2403 CreateOfferAsRemoteDescription();
2404 CreateAnswerAsLocalDescription();
2405
2406 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002407 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 pc_->local_streams()->at(0);
2409
2410 pc_->Close();
2411
2412 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002413 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414
2415 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002416 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002418 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419
2420 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2421
2422 EXPECT_TRUE(pc_->local_description() != NULL);
2423 EXPECT_TRUE(pc_->remote_description() != NULL);
2424
kwibergd1fe2812016-04-27 06:47:29 -07002425 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07002426 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002427 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07002428 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429
2430 std::string sdp;
2431 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2432 SessionDescriptionInterface* remote_offer =
2433 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2434 sdp, NULL);
2435 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
2436
2437 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2438 SessionDescriptionInterface* local_offer =
2439 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2440 sdp, NULL);
2441 EXPECT_FALSE(DoSetLocalDescription(local_offer));
2442}
2443
2444// Test that GetStats can still be called after PeerConnection::Close.
2445TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
2446 InitiateCall();
2447 pc_->Close();
2448 DoGetStats(NULL);
2449}
deadbeefab9b2d12015-10-14 11:33:11 -07002450
2451// NOTE: The series of tests below come from what used to be
2452// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2453// setting a remote or local description has the expected effects.
2454
2455// This test verifies that the remote MediaStreams corresponding to a received
2456// SDP string is created. In this test the two separate MediaStreams are
2457// signaled.
2458TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2459 FakeConstraints constraints;
2460 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2461 true);
2462 CreatePeerConnection(&constraints);
2463 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2464
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002465 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002466 EXPECT_TRUE(
2467 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2468 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2469 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2470
2471 // Create a session description based on another SDP with another
2472 // MediaStream.
2473 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
2474
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002475 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002476 EXPECT_TRUE(
2477 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2478}
2479
2480// This test verifies that when remote tracks are added/removed from SDP, the
2481// created remote streams are updated appropriately.
2482TEST_F(PeerConnectionInterfaceTest,
2483 AddRemoveTrackFromExistingRemoteMediaStream) {
2484 FakeConstraints constraints;
2485 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2486 true);
2487 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002488 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002489 CreateSessionDescriptionAndReference(1, 1);
deadbeefab9b2d12015-10-14 11:33:11 -07002490 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
2491 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2492 reference_collection_));
2493
2494 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002495 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002496 CreateSessionDescriptionAndReference(2, 2);
deadbeefab9b2d12015-10-14 11:33:11 -07002497 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
2498 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2499 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002500 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002501 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2502 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002503 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002504 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2505 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002506
2507 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002508 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002509 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002510 MockTrackObserver audio_track_observer(audio_track2);
2511 MockTrackObserver video_track_observer(video_track2);
2512
2513 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2514 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
deadbeefab9b2d12015-10-14 11:33:11 -07002515 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
2516 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2517 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002518 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002519 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002520 audio_track2->state(), kTimeout);
2521 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2522 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002523}
2524
2525// This tests that remote tracks are ended if a local session description is set
2526// that rejects the media content type.
2527TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
2528 FakeConstraints constraints;
2529 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2530 true);
2531 CreatePeerConnection(&constraints);
2532 // First create and set a remote offer, then reject its video content in our
2533 // answer.
2534 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2535 ASSERT_EQ(1u, observer_.remote_streams()->count());
2536 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2537 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2538 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2539
2540 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
2541 remote_stream->GetVideoTracks()[0];
2542 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
2543 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
2544 remote_stream->GetAudioTracks()[0];
2545 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2546
kwibergd1fe2812016-04-27 06:47:29 -07002547 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002548 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002549 cricket::ContentInfo* video_info =
2550 local_answer->description()->GetContentByName("video");
2551 video_info->rejected = true;
2552 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2553 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2554 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2555
2556 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002557 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002558 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002559 video_info = local_offer->description()->GetContentByName("video");
2560 ASSERT_TRUE(video_info != nullptr);
2561 video_info->rejected = true;
2562 cricket::ContentInfo* audio_info =
2563 local_offer->description()->GetContentByName("audio");
2564 ASSERT_TRUE(audio_info != nullptr);
2565 audio_info->rejected = true;
2566 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002567 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002568 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002569 remote_audio->state(), kTimeout);
2570 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2571 remote_video->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002572}
2573
2574// This tests that we won't crash if the remote track has been removed outside
2575// of PeerConnection and then PeerConnection tries to reject the track.
2576TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2577 FakeConstraints constraints;
2578 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2579 true);
2580 CreatePeerConnection(&constraints);
2581 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2582 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2583 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2584 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2585
kwibergd1fe2812016-04-27 06:47:29 -07002586 std::unique_ptr<SessionDescriptionInterface> local_answer(
deadbeefab9b2d12015-10-14 11:33:11 -07002587 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2588 kSdpStringWithStream1, nullptr));
2589 cricket::ContentInfo* video_info =
2590 local_answer->description()->GetContentByName("video");
2591 video_info->rejected = true;
2592 cricket::ContentInfo* audio_info =
2593 local_answer->description()->GetContentByName("audio");
2594 audio_info->rejected = true;
2595 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2596
2597 // No crash is a pass.
2598}
2599
deadbeef5e97fb52015-10-15 12:49:08 -07002600// This tests that if a recvonly remote description is set, no remote streams
2601// will be created, even if the description contains SSRCs/MSIDs.
2602// See: https://code.google.com/p/webrtc/issues/detail?id=5054
2603TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2604 FakeConstraints constraints;
2605 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2606 true);
2607 CreatePeerConnection(&constraints);
2608
2609 std::string recvonly_offer = kSdpStringWithStream1;
2610 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2611 strlen(kRecvonly), &recvonly_offer);
2612 CreateAndSetRemoteOffer(recvonly_offer);
2613
2614 EXPECT_EQ(0u, observer_.remote_streams()->count());
2615}
2616
deadbeefab9b2d12015-10-14 11:33:11 -07002617// This tests that a default MediaStream is created if a remote session
2618// description doesn't contain any streams and no MSID support.
2619// It also tests that the default stream is updated if a video m-line is added
2620// in a subsequent session description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002621TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002622 FakeConstraints constraints;
2623 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2624 true);
2625 CreatePeerConnection(&constraints);
2626 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2627
2628 ASSERT_EQ(1u, observer_.remote_streams()->count());
2629 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2630
2631 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2632 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2633 EXPECT_EQ("default", remote_stream->label());
2634
2635 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2636 ASSERT_EQ(1u, observer_.remote_streams()->count());
2637 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2638 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002639 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2640 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002641 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2642 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002643 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2644 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002645}
2646
2647// This tests that a default MediaStream is created if a remote session
2648// description doesn't contain any streams and media direction is send only.
2649TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002650 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002651 FakeConstraints constraints;
2652 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2653 true);
2654 CreatePeerConnection(&constraints);
2655 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2656
2657 ASSERT_EQ(1u, observer_.remote_streams()->count());
2658 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2659
2660 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2661 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2662 EXPECT_EQ("default", remote_stream->label());
2663}
2664
2665// This tests that it won't crash when PeerConnection tries to remove
2666// a remote track that as already been removed from the MediaStream.
2667TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2668 FakeConstraints constraints;
2669 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2670 true);
2671 CreatePeerConnection(&constraints);
2672 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2673 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2674 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2675 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2676
2677 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2678
2679 // No crash is a pass.
2680}
2681
2682// This tests that a default MediaStream is created if the remote session
2683// description doesn't contain any streams and don't contain an indication if
2684// MSID is supported.
2685TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002686 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002687 FakeConstraints constraints;
2688 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2689 true);
2690 CreatePeerConnection(&constraints);
2691 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2692
2693 ASSERT_EQ(1u, observer_.remote_streams()->count());
2694 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2695 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2696 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2697}
2698
2699// This tests that a default MediaStream is not created if the remote session
2700// description doesn't contain any streams but does support MSID.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002701TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002702 FakeConstraints constraints;
2703 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2704 true);
2705 CreatePeerConnection(&constraints);
2706 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2707 EXPECT_EQ(0u, observer_.remote_streams()->count());
2708}
2709
deadbeefbda7e0b2015-12-08 17:13:40 -08002710// This tests that when setting a new description, the old default tracks are
2711// not destroyed and recreated.
2712// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Stefan Holmer102362b2016-03-18 09:39:07 +01002713TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002714 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08002715 FakeConstraints constraints;
2716 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2717 true);
2718 CreatePeerConnection(&constraints);
2719 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2720
2721 ASSERT_EQ(1u, observer_.remote_streams()->count());
2722 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2723 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2724
2725 // Set the track to "disabled", then set a new description and ensure the
2726 // track is still disabled, which ensures it hasn't been recreated.
2727 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2728 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2729 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2730 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2731}
2732
deadbeefab9b2d12015-10-14 11:33:11 -07002733// This tests that a default MediaStream is not created if a remote session
2734// description is updated to not have any MediaStreams.
2735TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2736 FakeConstraints constraints;
2737 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2738 true);
2739 CreatePeerConnection(&constraints);
2740 CreateAndSetRemoteOffer(kSdpStringWithStream1);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002741 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002742 EXPECT_TRUE(
2743 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2744
2745 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2746 EXPECT_EQ(0u, observer_.remote_streams()->count());
2747}
2748
2749// This tests that an RtpSender is created when the local description is set
2750// after adding a local stream.
2751// TODO(deadbeef): This test and the one below it need to be updated when
2752// an RtpSender's lifetime isn't determined by when a local description is set.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002753TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002754 FakeConstraints constraints;
2755 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2756 true);
2757 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002758
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002759 // Create an offer with 1 stream with 2 tracks of each type.
2760 rtc::scoped_refptr<StreamCollection> stream_collection =
2761 CreateStreamCollection(1, 2);
2762 pc_->AddStream(stream_collection->at(0));
2763 std::unique_ptr<SessionDescriptionInterface> offer;
2764 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2765 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002766
deadbeefab9b2d12015-10-14 11:33:11 -07002767 auto senders = pc_->GetSenders();
2768 EXPECT_EQ(4u, senders.size());
2769 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2770 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2771 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2772 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2773
2774 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002775 pc_->RemoveStream(stream_collection->at(0));
2776 stream_collection = CreateStreamCollection(1, 1);
2777 pc_->AddStream(stream_collection->at(0));
2778 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2779 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2780
deadbeefab9b2d12015-10-14 11:33:11 -07002781 senders = pc_->GetSenders();
2782 EXPECT_EQ(2u, senders.size());
2783 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2784 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2785 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2786 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2787}
2788
2789// This tests that an RtpSender is created when the local description is set
2790// before adding a local stream.
2791TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002792 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002793 FakeConstraints constraints;
2794 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2795 true);
2796 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002797
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002798 rtc::scoped_refptr<StreamCollection> stream_collection =
2799 CreateStreamCollection(1, 2);
2800 // Add a stream to create the offer, but remove it afterwards.
2801 pc_->AddStream(stream_collection->at(0));
2802 std::unique_ptr<SessionDescriptionInterface> offer;
2803 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2804 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002805
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002806 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002807 auto senders = pc_->GetSenders();
2808 EXPECT_EQ(0u, senders.size());
2809
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002810 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002811 senders = pc_->GetSenders();
2812 EXPECT_EQ(4u, senders.size());
2813 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2814 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2815 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2816 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2817}
2818
2819// This tests that the expected behavior occurs if the SSRC on a local track is
2820// changed when SetLocalDescription is called.
2821TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002822 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07002823 FakeConstraints constraints;
2824 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2825 true);
2826 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002827
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002828 rtc::scoped_refptr<StreamCollection> stream_collection =
2829 CreateStreamCollection(2, 1);
2830 pc_->AddStream(stream_collection->at(0));
2831 std::unique_ptr<SessionDescriptionInterface> offer;
2832 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2833 // Grab a copy of the offer before it gets passed into the PC.
2834 std::unique_ptr<JsepSessionDescription> modified_offer(
2835 new JsepSessionDescription(JsepSessionDescription::kOffer));
2836 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
2837 offer->session_version());
2838 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002839
deadbeefab9b2d12015-10-14 11:33:11 -07002840 auto senders = pc_->GetSenders();
2841 EXPECT_EQ(2u, senders.size());
2842 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2843 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2844
2845 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002846 cricket::MediaContentDescription* desc =
2847 cricket::GetFirstAudioContentDescription(modified_offer->description());
2848 ASSERT_TRUE(desc != NULL);
2849 for (StreamParams& stream : desc->mutable_streams()) {
2850 for (unsigned int& ssrc : stream.ssrcs) {
2851 ++ssrc;
2852 }
2853 }
deadbeefab9b2d12015-10-14 11:33:11 -07002854
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002855 desc =
2856 cricket::GetFirstVideoContentDescription(modified_offer->description());
2857 ASSERT_TRUE(desc != NULL);
2858 for (StreamParams& stream : desc->mutable_streams()) {
2859 for (unsigned int& ssrc : stream.ssrcs) {
2860 ++ssrc;
2861 }
2862 }
2863
2864 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002865 senders = pc_->GetSenders();
2866 EXPECT_EQ(2u, senders.size());
2867 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2868 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2869 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2870 // changed.
2871}
2872
2873// This tests that the expected behavior occurs if a new session description is
2874// set with the same tracks, but on a different MediaStream.
Stefan Holmer55d6e7c2016-03-17 16:26:40 +01002875TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002876 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002877 FakeConstraints constraints;
2878 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2879 true);
2880 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002881
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002882 rtc::scoped_refptr<StreamCollection> stream_collection =
2883 CreateStreamCollection(2, 1);
2884 pc_->AddStream(stream_collection->at(0));
2885 std::unique_ptr<SessionDescriptionInterface> offer;
2886 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2887 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002888
deadbeefab9b2d12015-10-14 11:33:11 -07002889 auto senders = pc_->GetSenders();
2890 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002891 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2892 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002893
2894 // Add a new MediaStream but with the same tracks as in the first stream.
2895 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2896 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002897 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2898 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002899 pc_->AddStream(stream_1);
2900
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002901 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2902 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002903
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002904 auto new_senders = pc_->GetSenders();
2905 // Should be the same senders as before, but with updated stream id.
2906 // Note that this behavior is subject to change in the future.
2907 // We may decide the PC should ignore existing tracks in AddStream.
2908 EXPECT_EQ(senders, new_senders);
2909 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2910 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002911}
2912
zhihuang81c3a032016-11-17 12:06:24 -08002913// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
2914TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) {
2915 FakeConstraints constraints;
2916 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2917 true);
2918 CreatePeerConnection(&constraints);
2919 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2920 EXPECT_EQ(observer_.num_added_tracks_, 1);
2921 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2922
2923 // Create and set the updated remote SDP.
2924 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2925 EXPECT_EQ(observer_.num_added_tracks_, 2);
2926 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2927}
2928
deadbeefd1a38b52016-12-10 13:15:33 -08002929// Test that when SetConfiguration is called and the configuration is
2930// changing, the next offer causes an ICE restart.
2931TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingIceRetart) {
2932 PeerConnectionInterface::RTCConfiguration config;
2933 config.type = PeerConnectionInterface::kRelay;
2934 // Need to pass default constraints to prevent disabling of DTLS...
2935 FakeConstraints default_constraints;
2936 CreatePeerConnection(config, &default_constraints);
2937 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2938
2939 // Do initial offer/answer so there's something to restart.
2940 CreateOfferAsLocalDescription();
2941 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2942
2943 // Grab the ufrags.
2944 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2945
2946 // Change ICE policy, which should trigger an ICE restart on the next offer.
2947 config.type = PeerConnectionInterface::kAll;
2948 EXPECT_TRUE(pc_->SetConfiguration(config));
2949 CreateOfferAsLocalDescription();
2950
2951 // Grab the new ufrags.
2952 std::vector<std::string> subsequent_ufrags =
2953 GetUfrags(pc_->local_description());
2954
2955 // Sanity check.
2956 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
2957 // Check that each ufrag is different.
2958 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
2959 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
2960 }
2961}
2962
2963// Test that when SetConfiguration is called and the configuration *isn't*
2964// changing, the next offer does *not* cause an ICE restart.
2965TEST_F(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRetart) {
2966 PeerConnectionInterface::RTCConfiguration config;
2967 config.type = PeerConnectionInterface::kRelay;
2968 // Need to pass default constraints to prevent disabling of DTLS...
2969 FakeConstraints default_constraints;
2970 CreatePeerConnection(config, &default_constraints);
2971 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2972
2973 // Do initial offer/answer so there's something to restart.
2974 CreateOfferAsLocalDescription();
2975 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
2976
2977 // Grab the ufrags.
2978 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
2979
2980 // Call SetConfiguration with a config identical to what the PC was
2981 // constructed with.
2982 EXPECT_TRUE(pc_->SetConfiguration(config));
2983 CreateOfferAsLocalDescription();
2984
2985 // Grab the new ufrags.
2986 std::vector<std::string> subsequent_ufrags =
2987 GetUfrags(pc_->local_description());
2988
2989 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
2990}
2991
2992// Test for a weird corner case scenario:
2993// 1. Audio/video session established.
2994// 2. SetConfiguration changes ICE config; ICE restart needed.
2995// 3. ICE restart initiated by remote peer, but only for one m= section.
2996// 4. Next createOffer should initiate an ICE restart, but only for the other
2997// m= section; it would be pointless to do an ICE restart for the m= section
2998// that was already restarted.
2999TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
3000 PeerConnectionInterface::RTCConfiguration config;
3001 config.type = PeerConnectionInterface::kRelay;
3002 // Need to pass default constraints to prevent disabling of DTLS...
3003 FakeConstraints default_constraints;
3004 CreatePeerConnection(config, &default_constraints);
3005 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
3006
3007 // Do initial offer/answer so there's something to restart.
3008 CreateOfferAsLocalDescription();
3009 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
3010
3011 // Change ICE policy, which should set the "needs-ice-restart" flag.
3012 config.type = PeerConnectionInterface::kAll;
3013 EXPECT_TRUE(pc_->SetConfiguration(config));
3014
3015 // Do ICE restart for the first m= section, initiated by remote peer.
3016 webrtc::JsepSessionDescription* remote_offer =
3017 new webrtc::JsepSessionDescription(SessionDescriptionInterface::kOffer);
3018 EXPECT_TRUE(remote_offer->Initialize(kSdpStringWithStream1, nullptr));
3019 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3020 "modified";
3021 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3022 CreateAnswerAsLocalDescription();
3023
3024 // Grab the ufrags.
3025 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3026 ASSERT_EQ(2, initial_ufrags.size());
3027
3028 // Create offer and grab the new ufrags.
3029 CreateOfferAsLocalDescription();
3030 std::vector<std::string> subsequent_ufrags =
3031 GetUfrags(pc_->local_description());
3032 ASSERT_EQ(2, subsequent_ufrags.size());
3033
3034 // Ensure that only the ufrag for the second m= section changed.
3035 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3036 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3037}
3038
deadbeeffe4a8a42016-12-20 17:56:17 -08003039// Tests that the methods to return current/pending descriptions work as
3040// expected at different points in the offer/answer exchange. This test does
3041// one offer/answer exchange as the offerer, then another as the answerer.
3042TEST_F(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
3043 // This disables DTLS so we can apply an answer to ourselves.
3044 CreatePeerConnection();
3045
3046 // Create initial local offer and get SDP (which will also be used as
3047 // answer/pranswer);
3048 std::unique_ptr<SessionDescriptionInterface> offer;
3049 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3050 std::string sdp;
3051 EXPECT_TRUE(offer->ToString(&sdp));
3052
3053 // Set local offer.
3054 SessionDescriptionInterface* local_offer = offer.release();
3055 EXPECT_TRUE(DoSetLocalDescription(local_offer));
3056 EXPECT_EQ(local_offer, pc_->pending_local_description());
3057 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3058 EXPECT_EQ(nullptr, pc_->current_local_description());
3059 EXPECT_EQ(nullptr, pc_->current_remote_description());
3060
3061 // Set remote pranswer.
3062 SessionDescriptionInterface* remote_pranswer =
3063 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3064 sdp, nullptr);
3065 EXPECT_TRUE(DoSetRemoteDescription(remote_pranswer));
3066 EXPECT_EQ(local_offer, pc_->pending_local_description());
3067 EXPECT_EQ(remote_pranswer, pc_->pending_remote_description());
3068 EXPECT_EQ(nullptr, pc_->current_local_description());
3069 EXPECT_EQ(nullptr, pc_->current_remote_description());
3070
3071 // Set remote answer.
3072 SessionDescriptionInterface* remote_answer = webrtc::CreateSessionDescription(
3073 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3074 EXPECT_TRUE(DoSetRemoteDescription(remote_answer));
3075 EXPECT_EQ(nullptr, pc_->pending_local_description());
3076 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3077 EXPECT_EQ(local_offer, pc_->current_local_description());
3078 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3079
3080 // Set remote offer.
3081 SessionDescriptionInterface* remote_offer = webrtc::CreateSessionDescription(
3082 SessionDescriptionInterface::kOffer, sdp, nullptr);
3083 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3084 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3085 EXPECT_EQ(nullptr, pc_->pending_local_description());
3086 EXPECT_EQ(local_offer, pc_->current_local_description());
3087 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3088
3089 // Set local pranswer.
3090 SessionDescriptionInterface* local_pranswer =
3091 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3092 sdp, nullptr);
3093 EXPECT_TRUE(DoSetLocalDescription(local_pranswer));
3094 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3095 EXPECT_EQ(local_pranswer, pc_->pending_local_description());
3096 EXPECT_EQ(local_offer, pc_->current_local_description());
3097 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3098
3099 // Set local answer.
3100 SessionDescriptionInterface* local_answer = webrtc::CreateSessionDescription(
3101 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3102 EXPECT_TRUE(DoSetLocalDescription(local_answer));
3103 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3104 EXPECT_EQ(nullptr, pc_->pending_local_description());
3105 EXPECT_EQ(remote_offer, pc_->current_remote_description());
3106 EXPECT_EQ(local_answer, pc_->current_local_description());
3107}
3108
nisse51542be2016-02-12 02:27:06 -08003109class PeerConnectionMediaConfigTest : public testing::Test {
3110 protected:
3111 void SetUp() override {
nisseaf510af2016-03-21 08:20:42 -07003112 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
nisse51542be2016-02-12 02:27:06 -08003113 pcf_->Initialize();
3114 }
3115 const cricket::MediaConfig& TestCreatePeerConnection(
3116 const PeerConnectionInterface::RTCConfiguration& config,
3117 const MediaConstraintsInterface *constraints) {
3118 pcf_->create_media_controller_called_ = false;
3119
zhihuang9763d562016-08-05 11:14:50 -07003120 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3121 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003122 EXPECT_TRUE(pc.get());
3123 EXPECT_TRUE(pcf_->create_media_controller_called_);
3124 return pcf_->create_media_controller_config_;
3125 }
3126
zhihuang9763d562016-08-05 11:14:50 -07003127 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003128 MockPeerConnectionObserver observer_;
3129};
3130
3131// This test verifies the default behaviour with no constraints and a
3132// default RTCConfiguration.
3133TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3134 PeerConnectionInterface::RTCConfiguration config;
3135 FakeConstraints constraints;
3136
3137 const cricket::MediaConfig& media_config =
3138 TestCreatePeerConnection(config, &constraints);
3139
3140 EXPECT_FALSE(media_config.enable_dscp);
nisse0db023a2016-03-01 04:29:59 -08003141 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection);
3142 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing);
3143 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003144}
3145
3146// This test verifies the DSCP constraint is recognized and passed to
3147// the CreateMediaController call.
3148TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
3149 PeerConnectionInterface::RTCConfiguration config;
3150 FakeConstraints constraints;
3151
3152 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
3153 const cricket::MediaConfig& media_config =
3154 TestCreatePeerConnection(config, &constraints);
3155
3156 EXPECT_TRUE(media_config.enable_dscp);
3157}
3158
3159// This test verifies the cpu overuse detection constraint is
3160// recognized and passed to the CreateMediaController call.
3161TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
3162 PeerConnectionInterface::RTCConfiguration config;
3163 FakeConstraints constraints;
3164
3165 constraints.AddOptional(
3166 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
3167 const cricket::MediaConfig media_config =
3168 TestCreatePeerConnection(config, &constraints);
3169
nisse0db023a2016-03-01 04:29:59 -08003170 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection);
nisse51542be2016-02-12 02:27:06 -08003171}
3172
3173// This test verifies that the disable_prerenderer_smoothing flag is
3174// propagated from RTCConfiguration to the CreateMediaController call.
3175TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3176 PeerConnectionInterface::RTCConfiguration config;
3177 FakeConstraints constraints;
3178
Niels Möller71bdda02016-03-31 12:59:59 +02003179 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08003180 const cricket::MediaConfig& media_config =
3181 TestCreatePeerConnection(config, &constraints);
3182
nisse0db023a2016-03-01 04:29:59 -08003183 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing);
3184}
3185
3186// This test verifies the suspend below min bitrate constraint is
3187// recognized and passed to the CreateMediaController call.
3188TEST_F(PeerConnectionMediaConfigTest,
3189 TestSuspendBelowMinBitrateConstraintTrue) {
3190 PeerConnectionInterface::RTCConfiguration config;
3191 FakeConstraints constraints;
3192
3193 constraints.AddOptional(
3194 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3195 true);
3196 const cricket::MediaConfig media_config =
3197 TestCreatePeerConnection(config, &constraints);
3198
3199 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003200}
3201
deadbeefab9b2d12015-10-14 11:33:11 -07003202// The following tests verify that session options are created correctly.
deadbeefc80741f2015-10-22 13:14:45 -07003203// TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
3204// "verify options are converted correctly", should be "pass options into
3205// CreateOffer and verify the correct offer is produced."
deadbeefab9b2d12015-10-14 11:33:11 -07003206
3207TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
3208 RTCOfferAnswerOptions rtc_options;
3209 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3210
3211 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003212 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003213
3214 rtc_options.offer_to_receive_audio =
3215 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003216 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003217}
3218
3219TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
3220 RTCOfferAnswerOptions rtc_options;
3221 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3222
3223 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003224 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003225
3226 rtc_options.offer_to_receive_video =
3227 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003228 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003229}
3230
3231// Test that a MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003232// OfferToReceiveAudio and OfferToReceiveVideo options are set.
deadbeefab9b2d12015-10-14 11:33:11 -07003233TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
3234 RTCOfferAnswerOptions rtc_options;
3235 rtc_options.offer_to_receive_audio = 1;
3236 rtc_options.offer_to_receive_video = 1;
3237
3238 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003239 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003240 EXPECT_TRUE(options.has_audio());
3241 EXPECT_TRUE(options.has_video());
3242 EXPECT_TRUE(options.bundle_enabled);
3243}
3244
3245// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003246// OfferToReceiveAudio is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003247TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
3248 RTCOfferAnswerOptions rtc_options;
3249 rtc_options.offer_to_receive_audio = 1;
3250
3251 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003252 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003253 EXPECT_TRUE(options.has_audio());
3254 EXPECT_FALSE(options.has_video());
3255 EXPECT_TRUE(options.bundle_enabled);
3256}
3257
3258// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003259// the default OfferOptions are used.
deadbeefab9b2d12015-10-14 11:33:11 -07003260TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
3261 RTCOfferAnswerOptions rtc_options;
3262
3263 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003264 options.transport_options["audio"] = cricket::TransportOptions();
3265 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003266 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefc80741f2015-10-22 13:14:45 -07003267 EXPECT_TRUE(options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07003268 EXPECT_FALSE(options.has_video());
deadbeefc80741f2015-10-22 13:14:45 -07003269 EXPECT_TRUE(options.bundle_enabled);
deadbeefab9b2d12015-10-14 11:33:11 -07003270 EXPECT_TRUE(options.vad_enabled);
deadbeef0ed85b22016-02-23 17:24:52 -08003271 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3272 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003273}
3274
3275// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003276// OfferToReceiveVideo is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003277TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
3278 RTCOfferAnswerOptions rtc_options;
3279 rtc_options.offer_to_receive_audio = 0;
3280 rtc_options.offer_to_receive_video = 1;
3281
3282 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003283 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003284 EXPECT_FALSE(options.has_audio());
3285 EXPECT_TRUE(options.has_video());
3286 EXPECT_TRUE(options.bundle_enabled);
3287}
3288
3289// Test that a correct MediaSessionOptions is created for an offer if
3290// UseRtpMux is set to false.
3291TEST(CreateSessionOptionsTest,
3292 GetMediaSessionOptionsForOfferWithBundleDisabled) {
3293 RTCOfferAnswerOptions rtc_options;
3294 rtc_options.offer_to_receive_audio = 1;
3295 rtc_options.offer_to_receive_video = 1;
3296 rtc_options.use_rtp_mux = false;
3297
3298 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003299 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003300 EXPECT_TRUE(options.has_audio());
3301 EXPECT_TRUE(options.has_video());
3302 EXPECT_FALSE(options.bundle_enabled);
3303}
3304
3305// Test that a correct MediaSessionOptions is created to restart ice if
3306// IceRestart is set. It also tests that subsequent MediaSessionOptions don't
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003307// have |audio_transport_options.ice_restart| etc. set.
deadbeefab9b2d12015-10-14 11:33:11 -07003308TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
3309 RTCOfferAnswerOptions rtc_options;
3310 rtc_options.ice_restart = true;
3311
3312 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003313 options.transport_options["audio"] = cricket::TransportOptions();
3314 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003315 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003316 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
3317 EXPECT_TRUE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003318
3319 rtc_options = RTCOfferAnswerOptions();
htaaac2dea2016-03-10 13:35:55 -08003320 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003321 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3322 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003323}
3324
3325// Test that the MediaConstraints in an answer don't affect if audio and video
3326// is offered in an offer but that if kOfferToReceiveAudio or
3327// kOfferToReceiveVideo constraints are true in an offer, the media type will be
3328// included in subsequent answers.
3329TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
3330 FakeConstraints answer_c;
3331 answer_c.SetMandatoryReceiveAudio(true);
3332 answer_c.SetMandatoryReceiveVideo(true);
3333
3334 cricket::MediaSessionOptions answer_options;
3335 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
3336 EXPECT_TRUE(answer_options.has_audio());
3337 EXPECT_TRUE(answer_options.has_video());
3338
deadbeefc80741f2015-10-22 13:14:45 -07003339 RTCOfferAnswerOptions rtc_offer_options;
deadbeefab9b2d12015-10-14 11:33:11 -07003340
3341 cricket::MediaSessionOptions offer_options;
htaaac2dea2016-03-10 13:35:55 -08003342 EXPECT_TRUE(
3343 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
deadbeefc80741f2015-10-22 13:14:45 -07003344 EXPECT_TRUE(offer_options.has_audio());
htaaac2dea2016-03-10 13:35:55 -08003345 EXPECT_TRUE(offer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003346
deadbeefc80741f2015-10-22 13:14:45 -07003347 RTCOfferAnswerOptions updated_rtc_offer_options;
3348 updated_rtc_offer_options.offer_to_receive_audio = 1;
3349 updated_rtc_offer_options.offer_to_receive_video = 1;
deadbeefab9b2d12015-10-14 11:33:11 -07003350
3351 cricket::MediaSessionOptions updated_offer_options;
htaaac2dea2016-03-10 13:35:55 -08003352 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
htaa2a49d92016-03-04 02:51:39 -08003353 &updated_offer_options));
deadbeefab9b2d12015-10-14 11:33:11 -07003354 EXPECT_TRUE(updated_offer_options.has_audio());
3355 EXPECT_TRUE(updated_offer_options.has_video());
3356
3357 // Since an offer has been created with both audio and video, subsequent
3358 // offers and answers should contain both audio and video.
3359 // Answers will only contain the media types that exist in the offer
3360 // regardless of the value of |updated_answer_options.has_audio| and
3361 // |updated_answer_options.has_video|.
3362 FakeConstraints updated_answer_c;
3363 answer_c.SetMandatoryReceiveAudio(false);
3364 answer_c.SetMandatoryReceiveVideo(false);
3365
3366 cricket::MediaSessionOptions updated_answer_options;
3367 EXPECT_TRUE(
3368 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
3369 EXPECT_TRUE(updated_answer_options.has_audio());
3370 EXPECT_TRUE(updated_answer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003371}
deadbeef3edec7c2016-12-10 11:44:26 -08003372
deadbeef293e9262017-01-11 12:28:30 -08003373TEST(RTCErrorTypeTest, OstreamOperator) {
deadbeef3edec7c2016-12-10 11:44:26 -08003374 std::ostringstream oss;
deadbeef293e9262017-01-11 12:28:30 -08003375 oss << webrtc::RTCErrorType::NONE << ' '
3376 << webrtc::RTCErrorType::INVALID_PARAMETER << ' '
3377 << webrtc::RTCErrorType::INTERNAL_ERROR;
deadbeef3edec7c2016-12-10 11:44:26 -08003378 EXPECT_EQ("NONE INVALID_PARAMETER INTERNAL_ERROR", oss.str());
3379}
deadbeef293e9262017-01-11 12:28:30 -08003380
3381// Tests a few random fields being different.
3382TEST(RTCConfigurationTest, ComparisonOperators) {
3383 PeerConnectionInterface::RTCConfiguration a;
3384 PeerConnectionInterface::RTCConfiguration b;
3385 EXPECT_EQ(a, b);
3386
3387 PeerConnectionInterface::RTCConfiguration c;
3388 c.servers.push_back(PeerConnectionInterface::IceServer());
3389 EXPECT_NE(a, c);
3390
3391 PeerConnectionInterface::RTCConfiguration d;
3392 d.type = PeerConnectionInterface::kRelay;
3393 EXPECT_NE(a, d);
3394
3395 PeerConnectionInterface::RTCConfiguration e;
3396 e.audio_jitter_buffer_max_packets = 5;
3397 EXPECT_NE(a, e);
3398
3399 PeerConnectionInterface::RTCConfiguration f;
3400 f.ice_connection_receiving_timeout = 1337;
3401 EXPECT_NE(a, f);
3402
3403 PeerConnectionInterface::RTCConfiguration g;
3404 g.disable_ipv6 = true;
3405 EXPECT_NE(a, g);
3406
3407 PeerConnectionInterface::RTCConfiguration h(
3408 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3409 EXPECT_NE(a, h);
3410}