blob: 0e52c200d4df088ab0a37f4d5054294513f87c34 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
deadbeef3edec7c2016-12-10 11:44:26 -080012#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080014#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
kwiberg087bd342017-02-10 08:15:44 -080016#include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
ossueb1fde42017-05-02 06:46:30 -070017#include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/jsepsessiondescription.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010019#include "webrtc/api/mediastreaminterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010020#include "webrtc/api/peerconnectioninterface.h"
21#include "webrtc/api/rtpreceiverinterface.h"
22#include "webrtc/api/rtpsenderinterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#include "webrtc/api/test/fakeconstraints.h"
kjellandera96e2d72016-02-04 23:52:28 -080024#include "webrtc/media/base/fakevideocapturer.h"
zhihuang38ede132017-06-15 12:52:32 -070025#include "webrtc/media/engine/webrtcmediaengine.h"
deadbeef953c2ce2017-01-09 14:53:41 -080026#include "webrtc/media/sctp/sctptransportinternal.h"
peaha9cc40b2017-06-29 08:32:09 -070027#include "webrtc/modules/audio_processing/include/audio_processing.h"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070028#include "webrtc/p2p/base/fakeportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080029#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010030#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080031#include "webrtc/pc/mediastream.h"
32#include "webrtc/pc/peerconnection.h"
33#include "webrtc/pc/streamcollection.h"
34#include "webrtc/pc/test/fakertccertificategenerator.h"
35#include "webrtc/pc/test/fakevideotracksource.h"
36#include "webrtc/pc/test/mockpeerconnectionobservers.h"
37#include "webrtc/pc/test/testsdpstrings.h"
38#include "webrtc/pc/videocapturertracksource.h"
39#include "webrtc/pc/videotrack.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020040#include "webrtc/rtc_base/gunit.h"
41#include "webrtc/rtc_base/ssladapter.h"
42#include "webrtc/rtc_base/sslstreamadapter.h"
43#include "webrtc/rtc_base/stringutils.h"
44#include "webrtc/rtc_base/thread.h"
45#include "webrtc/rtc_base/virtualsocketserver.h"
kwibergac9f8762016-09-30 22:29:43 -070046#include "webrtc/test/gmock.h"
47
48#ifdef WEBRTC_ANDROID
ossu7bb87ee2017-01-23 04:56:25 -080049#include "webrtc/pc/test/androidtestinitializer.h"
kwibergac9f8762016-09-30 22:29:43 -070050#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52static const char kStreamLabel1[] = "local_stream_1";
53static const char kStreamLabel2[] = "local_stream_2";
54static const char kStreamLabel3[] = "local_stream_3";
55static const int kDefaultStunPort = 3478;
56static const char kStunAddressOnly[] = "stun:address";
57static const char kStunInvalidPort[] = "stun:address:-1";
58static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
59static const char kStunAddressPortAndMore2[] = "stun:address:port more";
60static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
61static const char kTurnUsername[] = "user";
62static const char kTurnPassword[] = "password";
63static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020064static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065
deadbeefab9b2d12015-10-14 11:33:11 -070066static const char kStreams[][8] = {"stream1", "stream2"};
67static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
68static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
69
deadbeef5e97fb52015-10-15 12:49:08 -070070static const char kRecvonly[] = "recvonly";
71static const char kSendrecv[] = "sendrecv";
72
deadbeefab9b2d12015-10-14 11:33:11 -070073// Reference SDP with a MediaStream with label "stream1" and audio track with
74// id "audio_1" and a video track with id "video_1;
75static const char kSdpStringWithStream1[] =
76 "v=0\r\n"
77 "o=- 0 0 IN IP4 127.0.0.1\r\n"
78 "s=-\r\n"
79 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080080 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070081 "a=ice-ufrag:e5785931\r\n"
82 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
83 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
84 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070085 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070086 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080087 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070088 "a=rtpmap:103 ISAC/16000\r\n"
89 "a=ssrc:1 cname:stream1\r\n"
90 "a=ssrc:1 mslabel:stream1\r\n"
91 "a=ssrc:1 label:audiotrack0\r\n"
92 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -080093 "a=ice-ufrag:e5785931\r\n"
94 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
95 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
96 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070097 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070098 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -080099 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700100 "a=rtpmap:120 VP8/90000\r\n"
101 "a=ssrc:2 cname:stream1\r\n"
102 "a=ssrc:2 mslabel:stream1\r\n"
103 "a=ssrc:2 label:videotrack0\r\n";
104
zhihuang81c3a032016-11-17 12:06:24 -0800105// Reference SDP with a MediaStream with label "stream1" and audio track with
106// id "audio_1";
107static const char kSdpStringWithStream1AudioTrackOnly[] =
108 "v=0\r\n"
109 "o=- 0 0 IN IP4 127.0.0.1\r\n"
110 "s=-\r\n"
111 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800112 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800113 "a=ice-ufrag:e5785931\r\n"
114 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
115 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
116 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800117 "a=mid:audio\r\n"
118 "a=sendrecv\r\n"
119 "a=rtpmap:103 ISAC/16000\r\n"
120 "a=ssrc:1 cname:stream1\r\n"
121 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800122 "a=ssrc:1 label:audiotrack0\r\n"
123 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800124
deadbeefab9b2d12015-10-14 11:33:11 -0700125// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
126// MediaStreams have one audio track and one video track.
127// This uses MSID.
128static const char kSdpStringWithStream1And2[] =
129 "v=0\r\n"
130 "o=- 0 0 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800133 "a=msid-semantic: WMS stream1 stream2\r\n"
134 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=ice-ufrag:e5785931\r\n"
136 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
137 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
138 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700139 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700140 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800141 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700142 "a=rtpmap:103 ISAC/16000\r\n"
143 "a=ssrc:1 cname:stream1\r\n"
144 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
145 "a=ssrc:3 cname:stream2\r\n"
146 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
147 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800148 "a=ice-ufrag:e5785931\r\n"
149 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
150 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
151 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700152 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700153 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800154 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700155 "a=rtpmap:120 VP8/0\r\n"
156 "a=ssrc:2 cname:stream1\r\n"
157 "a=ssrc:2 msid:stream1 videotrack0\r\n"
158 "a=ssrc:4 cname:stream2\r\n"
159 "a=ssrc:4 msid:stream2 videotrack1\r\n";
160
161// Reference SDP without MediaStreams. Msid is not supported.
162static const char kSdpStringWithoutStreams[] =
163 "v=0\r\n"
164 "o=- 0 0 IN IP4 127.0.0.1\r\n"
165 "s=-\r\n"
166 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800167 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700168 "a=ice-ufrag:e5785931\r\n"
169 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
170 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
171 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700172 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700173 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800174 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700175 "a=rtpmap:103 ISAC/16000\r\n"
176 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800177 "a=ice-ufrag:e5785931\r\n"
178 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
179 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
180 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700181 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700182 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800183 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700184 "a=rtpmap:120 VP8/90000\r\n";
185
186// Reference SDP without MediaStreams. Msid is supported.
187static const char kSdpStringWithMsidWithoutStreams[] =
188 "v=0\r\n"
189 "o=- 0 0 IN IP4 127.0.0.1\r\n"
190 "s=-\r\n"
191 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800192 "a=msid-semantic: WMS\r\n"
193 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700194 "a=ice-ufrag:e5785931\r\n"
195 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
196 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
197 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700198 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700199 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800200 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700201 "a=rtpmap:103 ISAC/16000\r\n"
202 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800203 "a=ice-ufrag:e5785931\r\n"
204 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
205 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
206 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700207 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700208 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800209 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700210 "a=rtpmap:120 VP8/90000\r\n";
211
212// Reference SDP without MediaStreams and audio only.
213static const char kSdpStringWithoutStreamsAudioOnly[] =
214 "v=0\r\n"
215 "o=- 0 0 IN IP4 127.0.0.1\r\n"
216 "s=-\r\n"
217 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800218 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=ice-ufrag:e5785931\r\n"
220 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
221 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
222 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700223 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700224 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800225 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700226 "a=rtpmap:103 ISAC/16000\r\n";
227
228// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
229static const char kSdpStringSendOnlyWithoutStreams[] =
230 "v=0\r\n"
231 "o=- 0 0 IN IP4 127.0.0.1\r\n"
232 "s=-\r\n"
233 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800234 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700235 "a=ice-ufrag:e5785931\r\n"
236 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
237 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
238 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700239 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700240 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700241 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800242 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700243 "a=rtpmap:103 ISAC/16000\r\n"
244 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800245 "a=ice-ufrag:e5785931\r\n"
246 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
247 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
248 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700249 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700250 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700251 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800252 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700253 "a=rtpmap:120 VP8/90000\r\n";
254
255static const char kSdpStringInit[] =
256 "v=0\r\n"
257 "o=- 0 0 IN IP4 127.0.0.1\r\n"
258 "s=-\r\n"
259 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700260 "a=msid-semantic: WMS\r\n";
261
262static const char kSdpStringAudio[] =
263 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800264 "a=ice-ufrag:e5785931\r\n"
265 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
266 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
267 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700268 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700269 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800270 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700271 "a=rtpmap:103 ISAC/16000\r\n";
272
273static const char kSdpStringVideo[] =
274 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800275 "a=ice-ufrag:e5785931\r\n"
276 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
277 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
278 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700279 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700280 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800281 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700282 "a=rtpmap:120 VP8/90000\r\n";
283
284static const char kSdpStringMs1Audio0[] =
285 "a=ssrc:1 cname:stream1\r\n"
286 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
287
288static const char kSdpStringMs1Video0[] =
289 "a=ssrc:2 cname:stream1\r\n"
290 "a=ssrc:2 msid:stream1 videotrack0\r\n";
291
292static const char kSdpStringMs1Audio1[] =
293 "a=ssrc:3 cname:stream1\r\n"
294 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
295
296static const char kSdpStringMs1Video1[] =
297 "a=ssrc:4 cname:stream1\r\n"
298 "a=ssrc:4 msid:stream1 videotrack1\r\n";
299
deadbeef8662f942017-01-20 21:20:51 -0800300static const char kDtlsSdesFallbackSdp[] =
301 "v=0\r\n"
302 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
303 "s=-\r\n"
304 "c=IN IP4 0.0.0.0\r\n"
305 "t=0 0\r\n"
306 "a=group:BUNDLE audio\r\n"
307 "a=msid-semantic: WMS\r\n"
308 "m=audio 1 RTP/SAVPF 0\r\n"
309 "a=sendrecv\r\n"
310 "a=rtcp-mux\r\n"
311 "a=mid:audio\r\n"
312 "a=ssrc:1 cname:stream1\r\n"
313 "a=ssrc:1 mslabel:stream1\r\n"
314 "a=ssrc:1 label:audiotrack0\r\n"
315 "a=ice-ufrag:e5785931\r\n"
316 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
317 "a=rtpmap:0 pcmu/8000\r\n"
318 "a=fingerprint:sha-1 "
319 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
320 "a=setup:actpass\r\n"
321 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 "
322 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
323 "dummy_session_params\r\n";
324
perkjd61bf802016-03-24 03:16:19 -0700325using ::testing::Exactly;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700326using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700328using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329using webrtc::AudioTrackInterface;
330using webrtc::DataBuffer;
331using webrtc::DataChannelInterface;
332using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333using webrtc::IceCandidateInterface;
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700334using webrtc::JsepSessionDescription;
deadbeefc80741f2015-10-22 13:14:45 -0700335using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700336using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337using webrtc::MediaStreamInterface;
338using webrtc::MediaStreamTrackInterface;
339using webrtc::MockCreateSessionDescriptionObserver;
340using webrtc::MockDataChannelObserver;
341using webrtc::MockSetSessionDescriptionObserver;
342using webrtc::MockStatsObserver;
perkjd61bf802016-03-24 03:16:19 -0700343using webrtc::NotifierInterface;
344using webrtc::ObserverInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345using webrtc::PeerConnectionInterface;
346using webrtc::PeerConnectionObserver;
deadbeef293e9262017-01-11 12:28:30 -0800347using webrtc::RTCError;
348using webrtc::RTCErrorType;
deadbeefab9b2d12015-10-14 11:33:11 -0700349using webrtc::RtpReceiverInterface;
350using webrtc::RtpSenderInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351using webrtc::SdpParseError;
352using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700353using webrtc::StreamCollection;
354using webrtc::StreamCollectionInterface;
perkja3ede6c2016-03-08 01:27:48 +0100355using webrtc::VideoTrackSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700356using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357using webrtc::VideoTrackInterface;
358
deadbeefab9b2d12015-10-14 11:33:11 -0700359typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
360
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361namespace {
362
363// Gets the first ssrc of given content type from the ContentInfo.
364bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
365 if (!content_info || !ssrc) {
366 return false;
367 }
368 const cricket::MediaContentDescription* media_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000369 static_cast<const cricket::MediaContentDescription*>(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 content_info->description);
371 if (!media_desc || media_desc->streams().empty()) {
372 return false;
373 }
374 *ssrc = media_desc->streams().begin()->first_ssrc();
375 return true;
376}
377
deadbeefd1a38b52016-12-10 13:15:33 -0800378// Get the ufrags out of an SDP blob. Useful for testing ICE restart
379// behavior.
380std::vector<std::string> GetUfrags(
381 const webrtc::SessionDescriptionInterface* desc) {
382 std::vector<std::string> ufrags;
383 for (const cricket::TransportInfo& info :
384 desc->description()->transport_infos()) {
385 ufrags.push_back(info.description.ice_ufrag);
386 }
387 return ufrags;
388}
389
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390void SetSsrcToZero(std::string* sdp) {
391 const char kSdpSsrcAtribute[] = "a=ssrc:";
392 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
393 size_t ssrc_pos = 0;
394 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
395 std::string::npos) {
396 size_t end_ssrc = sdp->find(" ", ssrc_pos);
397 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
398 ssrc_pos = end_ssrc;
399 }
400}
401
deadbeefab9b2d12015-10-14 11:33:11 -0700402// Check if |streams| contains the specified track.
403bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
404 const std::string& stream_label,
405 const std::string& track_id) {
406 for (const cricket::StreamParams& params : streams) {
407 if (params.sync_label == stream_label && params.id == track_id) {
408 return true;
409 }
410 }
411 return false;
412}
413
414// Check if |senders| contains the specified sender, by id.
415bool ContainsSender(
416 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
417 const std::string& id) {
418 for (const auto& sender : senders) {
419 if (sender->id() == id) {
420 return true;
421 }
422 }
423 return false;
424}
425
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700426// Check if |senders| contains the specified sender, by id and stream id.
427bool ContainsSender(
428 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
429 const std::string& id,
430 const std::string& stream_id) {
431 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700432 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700433 return true;
434 }
435 }
436 return false;
437}
438
deadbeefab9b2d12015-10-14 11:33:11 -0700439// Create a collection of streams.
440// CreateStreamCollection(1) creates a collection that
441// correspond to kSdpStringWithStream1.
442// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
443rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700444 int number_of_streams,
445 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700446 rtc::scoped_refptr<StreamCollection> local_collection(
447 StreamCollection::Create());
448
449 for (int i = 0; i < number_of_streams; ++i) {
450 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
451 webrtc::MediaStream::Create(kStreams[i]));
452
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700453 for (int j = 0; j < tracks_per_stream; ++j) {
454 // Add a local audio track.
455 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
456 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
457 nullptr));
458 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700459
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700460 // Add a local video track.
461 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
462 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700463 webrtc::FakeVideoTrackSource::Create(),
464 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700465 stream->AddTrack(video_track);
466 }
deadbeefab9b2d12015-10-14 11:33:11 -0700467
468 local_collection->AddStream(stream);
469 }
470 return local_collection;
471}
472
473// Check equality of StreamCollections.
474bool CompareStreamCollections(StreamCollectionInterface* s1,
475 StreamCollectionInterface* s2) {
476 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
477 return false;
478 }
479
480 for (size_t i = 0; i != s1->count(); ++i) {
481 if (s1->at(i)->label() != s2->at(i)->label()) {
482 return false;
483 }
484 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
485 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
486 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
487 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
488
489 if (audio_tracks1.size() != audio_tracks2.size()) {
490 return false;
491 }
492 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
493 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
494 return false;
495 }
496 }
497 if (video_tracks1.size() != video_tracks2.size()) {
498 return false;
499 }
500 for (size_t j = 0; j != video_tracks1.size(); ++j) {
501 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
502 return false;
503 }
504 }
505 }
506 return true;
507}
508
perkjd61bf802016-03-24 03:16:19 -0700509// Helper class to test Observer.
510class MockTrackObserver : public ObserverInterface {
511 public:
512 explicit MockTrackObserver(NotifierInterface* notifier)
513 : notifier_(notifier) {
514 notifier_->RegisterObserver(this);
515 }
516
517 ~MockTrackObserver() { Unregister(); }
518
519 void Unregister() {
520 if (notifier_) {
521 notifier_->UnregisterObserver(this);
522 notifier_ = nullptr;
523 }
524 }
525
526 MOCK_METHOD0(OnChanged, void());
527
528 private:
529 NotifierInterface* notifier_;
530};
531
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532class MockPeerConnectionObserver : public PeerConnectionObserver {
533 public:
deadbeefab9b2d12015-10-14 11:33:11 -0700534 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200535 virtual ~MockPeerConnectionObserver() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 }
537 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
538 pc_ = pc;
539 if (pc) {
540 state_ = pc_->signaling_state();
541 }
542 }
nisseef8b61e2016-04-29 06:09:15 -0700543 void OnSignalingChange(
544 PeerConnectionInterface::SignalingState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 EXPECT_EQ(pc_->signaling_state(), new_state);
546 state_ = new_state;
547 }
deadbeefab9b2d12015-10-14 11:33:11 -0700548
549 MediaStreamInterface* RemoteStream(const std::string& label) {
550 return remote_streams_->find(label);
551 }
552 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700553 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 last_added_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700555 remote_streams_->AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700557 void OnRemoveStream(
558 rtc::scoped_refptr<MediaStreamInterface> stream) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 last_removed_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700560 remote_streams_->RemoveStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 }
perkjdfb769d2016-02-09 03:09:43 -0800562 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
Taylor Brandstetter98cde262016-05-31 13:02:21 -0700563 void OnDataChannel(
564 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 last_datachannel_ = data_channel;
566 }
567
perkjdfb769d2016-02-09 03:09:43 -0800568 void OnIceConnectionChange(
569 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 EXPECT_EQ(pc_->ice_connection_state(), new_state);
zhihuang81c3a032016-11-17 12:06:24 -0800571 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 }
perkjdfb769d2016-02-09 03:09:43 -0800573 void OnIceGatheringChange(
574 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
perkjdfb769d2016-02-09 03:09:43 -0800576 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete;
zhihuang81c3a032016-11-17 12:06:24 -0800577 callback_triggered_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 }
perkjdfb769d2016-02-09 03:09:43 -0800579 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
581 pc_->ice_gathering_state());
582
583 std::string sdp;
584 EXPECT_TRUE(candidate->ToString(&sdp));
585 EXPECT_LT(0u, sdp.size());
586 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
587 candidate->sdp_mline_index(), sdp, NULL));
588 EXPECT_TRUE(last_candidate_.get() != NULL);
zhihuang81c3a032016-11-17 12:06:24 -0800589 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700590 }
591
592 void OnIceCandidatesRemoved(
593 const std::vector<cricket::Candidate>& candidates) override {
zhihuang81c3a032016-11-17 12:06:24 -0800594 callback_triggered_ = true;
zhihuang29ff8442016-07-27 11:07:25 -0700595 }
596
597 void OnIceConnectionReceivingChange(bool receiving) override {
zhihuang81c3a032016-11-17 12:06:24 -0800598 callback_triggered_ = true;
599 }
600
zhihuangc63b8942016-12-02 15:41:10 -0800601 void OnAddTrack(
602 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
603 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
604 streams) override {
zhihuang81c3a032016-11-17 12:06:24 -0800605 EXPECT_TRUE(receiver != nullptr);
606 num_added_tracks_++;
607 last_added_track_label_ = receiver->id();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609
610 // Returns the label of the last added stream.
611 // Empty string if no stream have been added.
612 std::string GetLastAddedStreamLabel() {
613 if (last_added_stream_.get())
614 return last_added_stream_->label();
615 return "";
616 }
617 std::string GetLastRemovedStreamLabel() {
618 if (last_removed_stream_.get())
619 return last_removed_stream_->label();
620 return "";
621 }
622
zhihuang9763d562016-08-05 11:14:50 -0700623 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 PeerConnectionInterface::SignalingState state_;
kwibergd1fe2812016-04-27 06:47:29 -0700625 std::unique_ptr<IceCandidateInterface> last_candidate_;
zhihuang9763d562016-08-05 11:14:50 -0700626 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
deadbeefab9b2d12015-10-14 11:33:11 -0700627 rtc::scoped_refptr<StreamCollection> remote_streams_;
628 bool renegotiation_needed_ = false;
629 bool ice_complete_ = false;
zhihuang81c3a032016-11-17 12:06:24 -0800630 bool callback_triggered_ = false;
631 int num_added_tracks_ = 0;
632 std::string last_added_track_label_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634 private:
zhihuang9763d562016-08-05 11:14:50 -0700635 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
636 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637};
638
639} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700640
nisse528b7932017-05-08 03:21:43 -0700641// The PeerConnectionMediaConfig tests below verify that configuration and
642// constraints are propagated into the PeerConnection's MediaConfig. These
643// settings are intended for MediaChannel constructors, but that is not
644// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700645class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
646 public:
zhihuang38ede132017-06-15 12:52:32 -0700647 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
648 CreatePeerConnectionFactoryForTest() {
649 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
650 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
651
652 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
653 cricket::WebRtcMediaEngineFactory::Create(
654 nullptr, audio_encoder_factory, audio_decoder_factory, nullptr,
peaha9cc40b2017-06-29 08:32:09 -0700655 nullptr, nullptr, webrtc::AudioProcessing::Create()));
zhihuang38ede132017-06-15 12:52:32 -0700656
657 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
658 webrtc::CreateCallFactory();
659
660 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
661 webrtc::CreateRtcEventLogFactory();
662
663 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
664 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
665 nullptr, audio_encoder_factory, audio_decoder_factory, nullptr, nullptr,
666 nullptr, std::move(media_engine), std::move(call_factory),
667 std::move(event_log_factory));
668 }
669
670 PeerConnectionFactoryForTest(
671 rtc::Thread* network_thread,
672 rtc::Thread* worker_thread,
673 rtc::Thread* signaling_thread,
674 webrtc::AudioDeviceModule* default_adm,
675 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
676 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
677 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
678 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
679 rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
680 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
681 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
682 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
683 : webrtc::PeerConnectionFactory(network_thread,
684 worker_thread,
685 signaling_thread,
686 default_adm,
687 audio_encoder_factory,
688 audio_decoder_factory,
689 video_encoder_factory,
690 video_decoder_factory,
691 audio_mixer,
692 std::move(media_engine),
693 std::move(call_factory),
694 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800695
zhihuang29ff8442016-07-27 11:07:25 -0700696 cricket::TransportController* CreateTransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700697 cricket::PortAllocator* port_allocator,
698 bool redetermine_role_on_ice_restart) override {
zhihuang29ff8442016-07-27 11:07:25 -0700699 transport_controller = new cricket::TransportController(
Honghai Zhangbfd398c2016-08-30 22:07:42 -0700700 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
deadbeef7914b8c2017-04-21 03:23:33 -0700701 redetermine_role_on_ice_restart, rtc::CryptoOptions());
zhihuang29ff8442016-07-27 11:07:25 -0700702 return transport_controller;
703 }
704
705 cricket::TransportController* transport_controller;
zhihuang29ff8442016-07-27 11:07:25 -0700706};
707
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708class PeerConnectionInterfaceTest : public testing::Test {
709 protected:
deadbeef9a6f4d42017-05-15 19:43:33 -0700710 PeerConnectionInterfaceTest()
deadbeef98e186c2017-05-16 18:00:06 -0700711 : vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) {
phoglund37ebcf02016-01-08 05:04:57 -0800712#ifdef WEBRTC_ANDROID
713 webrtc::InitializeAndroidObjects();
714#endif
715 }
716
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 virtual void SetUp() {
718 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700719 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
720 nullptr, nullptr, nullptr);
721 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700722 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700723 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700724 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 }
726
727 void CreatePeerConnection() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700728 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 }
730
deadbeef293e9262017-01-11 12:28:30 -0800731 // DTLS does not work in a loopback call, so is disabled for most of the
732 // tests in this file.
733 void CreatePeerConnectionWithoutDtls() {
734 FakeConstraints no_dtls_constraints;
735 no_dtls_constraints.AddMandatory(
736 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
737
738 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
739 &no_dtls_constraints);
740 }
741
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700743 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
744 constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 }
746
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700747 void CreatePeerConnectionWithIceTransportsType(
748 PeerConnectionInterface::IceTransportsType type) {
749 PeerConnectionInterface::RTCConfiguration config;
750 config.type = type;
751 return CreatePeerConnection(config, nullptr);
752 }
753
754 void CreatePeerConnectionWithIceServer(const std::string& uri,
755 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800756 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700758 server.uri = uri;
759 server.password = password;
760 config.servers.push_back(server);
761 CreatePeerConnection(config, nullptr);
762 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700764 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
765 webrtc::MediaConstraintsInterface* constraints) {
kwibergd1fe2812016-04-27 06:47:29 -0700766 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800767 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
768 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000769
deadbeef1dcb1642017-03-29 21:08:16 -0700770 // Create certificate generator unless DTLS constraint is explicitly set to
771 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200772 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000773 bool dtls;
774 if (FindConstraint(constraints,
775 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
776 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200777 nullptr) && dtls) {
deadbeef8662f942017-01-20 21:20:51 -0800778 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
779 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000780 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200781 pc_ = pc_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800782 config, constraints, std::move(port_allocator),
Henrik Boströmd79599d2016-06-01 13:58:50 +0200783 std::move(cert_generator), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 ASSERT_TRUE(pc_.get() != NULL);
785 observer_.SetPeerConnectionInterface(pc_.get());
786 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
787 }
788
deadbeef0a6c4ca2015-10-06 11:38:28 -0700789 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800790 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700791 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700792 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800793 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700794
zhihuang9763d562016-08-05 11:14:50 -0700795 rtc::scoped_refptr<PeerConnectionInterface> pc;
hbosd7973cc2016-05-27 06:08:53 -0700796 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
797 &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700799 }
800
Steve Anton038834f2017-07-14 15:59:59 -0700801 void CreatePeerConnectionExpectFail(
802 PeerConnectionInterface::RTCConfiguration config) {
803 PeerConnectionInterface::IceServer server;
804 server.uri = kTurnIceServerUri;
805 server.password = kTurnPassword;
806 config.servers.push_back(server);
807 rtc::scoped_refptr<PeerConnectionInterface> pc =
808 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
809 EXPECT_EQ(nullptr, pc);
810 }
811
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700813 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800814 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
815 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
816 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800818 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819
deadbeef0a6c4ca2015-10-06 11:38:28 -0700820 CreatePeerConnectionExpectFail(kStunInvalidPort);
821 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
822 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700824 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800825 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
826 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800828 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800830 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800832 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 }
834
835 void ReleasePeerConnection() {
836 pc_ = NULL;
837 observer_.SetPeerConnectionInterface(NULL);
838 }
839
deadbeefab9b2d12015-10-14 11:33:11 -0700840 void AddVideoStream(const std::string& label) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700842 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700844 rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
deadbeef112b2e92017-02-10 20:13:37 -0800845 pc_factory_->CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(
846 new cricket::FakeVideoCapturer()),
847 NULL));
zhihuang9763d562016-08-05 11:14:50 -0700848 rtc::scoped_refptr<VideoTrackInterface> video_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 pc_factory_->CreateVideoTrack(label + "v0", video_source));
850 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000851 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
853 observer_.renegotiation_needed_ = false;
854 }
855
856 void AddVoiceStream(const std::string& label) {
857 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700858 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 pc_factory_->CreateLocalMediaStream(label));
zhihuang9763d562016-08-05 11:14:50 -0700860 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 pc_factory_->CreateAudioTrack(label + "a0", NULL));
862 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000863 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
865 observer_.renegotiation_needed_ = false;
866 }
867
868 void AddAudioVideoStream(const std::string& stream_label,
869 const std::string& audio_track_label,
870 const std::string& video_track_label) {
871 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700872 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 pc_factory_->CreateLocalMediaStream(stream_label));
zhihuang9763d562016-08-05 11:14:50 -0700874 rtc::scoped_refptr<AudioTrackInterface> audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 pc_factory_->CreateAudioTrack(
876 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
877 stream->AddTrack(audio_track.get());
zhihuang9763d562016-08-05 11:14:50 -0700878 rtc::scoped_refptr<VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -0700879 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -0800880 video_track_label, pc_factory_->CreateVideoSource(
881 std::unique_ptr<cricket::VideoCapturer>(
882 new cricket::FakeVideoCapturer()))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000884 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
886 observer_.renegotiation_needed_ = false;
887 }
888
kwibergd1fe2812016-04-27 06:47:29 -0700889 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700890 bool offer,
891 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000892 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
893 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 MockCreateSessionDescriptionObserver>());
895 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700896 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700898 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 }
900 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700901 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 return observer->result();
903 }
904
kwibergd1fe2812016-04-27 06:47:29 -0700905 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700906 MediaConstraintsInterface* constraints) {
907 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 }
909
kwibergd1fe2812016-04-27 06:47:29 -0700910 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
deadbeefc80741f2015-10-22 13:14:45 -0700911 MediaConstraintsInterface* constraints) {
912 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 }
914
915 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000916 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
917 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 MockSetSessionDescriptionObserver>());
919 if (local) {
920 pc_->SetLocalDescription(observer, desc);
921 } else {
922 pc_->SetRemoteDescription(observer, desc);
923 }
zhihuang29ff8442016-07-27 11:07:25 -0700924 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
925 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
926 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 return observer->result();
928 }
929
930 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
931 return DoSetSessionDescription(desc, true);
932 }
933
934 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
935 return DoSetSessionDescription(desc, false);
936 }
937
938 // Calls PeerConnection::GetStats and check the return value.
939 // It does not verify the values in the StatReports since a RTCP packet might
940 // be required.
941 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000942 rtc::scoped_refptr<MockStatsObserver> observer(
943 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000944 if (!pc_->GetStats(
945 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 return false;
947 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
948 return observer->called();
949 }
950
951 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800952 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 // Create a local stream with audio&video tracks.
954 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
955 CreateOfferReceiveAnswer();
956 }
957
958 // Verify that RTP Header extensions has been negotiated for audio and video.
959 void VerifyRemoteRtpHeaderExtensions() {
960 const cricket::MediaContentDescription* desc =
961 cricket::GetFirstAudioContentDescription(
962 pc_->remote_description()->description());
963 ASSERT_TRUE(desc != NULL);
964 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
965
966 desc = cricket::GetFirstVideoContentDescription(
967 pc_->remote_description()->description());
968 ASSERT_TRUE(desc != NULL);
969 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
970 }
971
972 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700973 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700974 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 std::string sdp;
976 EXPECT_TRUE(offer->ToString(&sdp));
977 SessionDescriptionInterface* remote_offer =
978 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
979 sdp, NULL);
980 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
981 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
982 }
983
deadbeefab9b2d12015-10-14 11:33:11 -0700984 void CreateAndSetRemoteOffer(const std::string& sdp) {
985 SessionDescriptionInterface* remote_offer =
986 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
987 sdp, nullptr);
988 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
989 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
990 }
991
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700993 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700994 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995
996 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
997 // audio codec change, even if the parameter has nothing to do with
998 // receiving. Not all parameters are serialized to SDP.
999 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1000 // the SessionDescription, it is necessary to do that here to in order to
1001 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1002 // https://code.google.com/p/webrtc/issues/detail?id=1356
1003 std::string sdp;
1004 EXPECT_TRUE(answer->ToString(&sdp));
1005 SessionDescriptionInterface* new_answer =
1006 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
1007 sdp, NULL);
1008 EXPECT_TRUE(DoSetLocalDescription(new_answer));
1009 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1010 }
1011
1012 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001013 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001014 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015
1016 std::string sdp;
1017 EXPECT_TRUE(answer->ToString(&sdp));
1018 SessionDescriptionInterface* pr_answer =
1019 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
1020 sdp, NULL);
1021 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
1022 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1023 }
1024
1025 void CreateOfferReceiveAnswer() {
1026 CreateOfferAsLocalDescription();
1027 std::string sdp;
1028 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1029 CreateAnswerAsRemoteDescription(sdp);
1030 }
1031
1032 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001033 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001034 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1036 // audio codec change, even if the parameter has nothing to do with
1037 // receiving. Not all parameters are serialized to SDP.
1038 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1039 // the SessionDescription, it is necessary to do that here to in order to
1040 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1041 // https://code.google.com/p/webrtc/issues/detail?id=1356
1042 std::string sdp;
1043 EXPECT_TRUE(offer->ToString(&sdp));
1044 SessionDescriptionInterface* new_offer =
1045 webrtc::CreateSessionDescription(
1046 SessionDescriptionInterface::kOffer,
1047 sdp, NULL);
1048
1049 EXPECT_TRUE(DoSetLocalDescription(new_offer));
1050 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001051 // Wait for the ice_complete message, so that SDP will have candidates.
1052 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 }
1054
deadbeefab9b2d12015-10-14 11:33:11 -07001055 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1057 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001058 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 EXPECT_TRUE(DoSetRemoteDescription(answer));
1060 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1061 }
1062
deadbeefab9b2d12015-10-14 11:33:11 -07001063 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 webrtc::JsepSessionDescription* pr_answer =
1065 new webrtc::JsepSessionDescription(
1066 SessionDescriptionInterface::kPrAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001067 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
1069 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
1070 webrtc::JsepSessionDescription* answer =
1071 new webrtc::JsepSessionDescription(
1072 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -07001073 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 EXPECT_TRUE(DoSetRemoteDescription(answer));
1075 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1076 }
1077
1078 // Help function used for waiting until a the last signaled remote stream has
1079 // the same label as |stream_label|. In a few of the tests in this file we
1080 // answer with the same session description as we offer and thus we can
1081 // check if OnAddStream have been called with the same stream as we offer to
1082 // send.
1083 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
1084 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
1085 }
1086
1087 // Creates an offer and applies it as a local session description.
1088 // Creates an answer with the same SDP an the offer but removes all lines
1089 // that start with a:ssrc"
1090 void CreateOfferReceiveAnswerWithoutSsrc() {
1091 CreateOfferAsLocalDescription();
1092 std::string sdp;
1093 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1094 SetSsrcToZero(&sdp);
1095 CreateAnswerAsRemoteDescription(sdp);
1096 }
1097
deadbeefab9b2d12015-10-14 11:33:11 -07001098 // This function creates a MediaStream with label kStreams[0] and
1099 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1100 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001101 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001102 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001103 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001104 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1105 size_t number_of_video_tracks) {
1106 EXPECT_LE(number_of_audio_tracks, 2u);
1107 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001108
1109 reference_collection_ = StreamCollection::Create();
1110 std::string sdp_ms1 = std::string(kSdpStringInit);
1111
1112 std::string mediastream_label = kStreams[0];
1113
1114 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1115 webrtc::MediaStream::Create(mediastream_label));
1116 reference_collection_->AddStream(stream);
1117
1118 if (number_of_audio_tracks > 0) {
1119 sdp_ms1 += std::string(kSdpStringAudio);
1120 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1121 AddAudioTrack(kAudioTracks[0], stream);
1122 }
1123 if (number_of_audio_tracks > 1) {
1124 sdp_ms1 += kSdpStringMs1Audio1;
1125 AddAudioTrack(kAudioTracks[1], stream);
1126 }
1127
1128 if (number_of_video_tracks > 0) {
1129 sdp_ms1 += std::string(kSdpStringVideo);
1130 sdp_ms1 += std::string(kSdpStringMs1Video0);
1131 AddVideoTrack(kVideoTracks[0], stream);
1132 }
1133 if (number_of_video_tracks > 1) {
1134 sdp_ms1 += kSdpStringMs1Video1;
1135 AddVideoTrack(kVideoTracks[1], stream);
1136 }
1137
kwibergd1fe2812016-04-27 06:47:29 -07001138 return std::unique_ptr<SessionDescriptionInterface>(
kwiberg2bbff992016-03-16 11:03:04 -07001139 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1140 sdp_ms1, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001141 }
1142
1143 void AddAudioTrack(const std::string& track_id,
1144 MediaStreamInterface* stream) {
1145 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1146 webrtc::AudioTrack::Create(track_id, nullptr));
1147 ASSERT_TRUE(stream->AddTrack(audio_track));
1148 }
1149
1150 void AddVideoTrack(const std::string& track_id,
1151 MediaStreamInterface* stream) {
1152 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001153 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001154 webrtc::FakeVideoTrackSource::Create(),
1155 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001156 ASSERT_TRUE(stream->AddTrack(video_track));
1157 }
1158
kwibergfd8be342016-05-14 19:44:11 -07001159 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
deadbeef293e9262017-01-11 12:28:30 -08001160 CreatePeerConnectionWithoutDtls();
zhihuang8f65cdf2016-05-06 18:40:30 -07001161 AddVoiceStream(kStreamLabel1);
kwibergfd8be342016-05-14 19:44:11 -07001162 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001163 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1164 return offer;
1165 }
1166
kwibergfd8be342016-05-14 19:44:11 -07001167 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001168 CreateAnswerWithOneAudioStream() {
kwibergfd8be342016-05-14 19:44:11 -07001169 std::unique_ptr<SessionDescriptionInterface> offer =
zhihuang8f65cdf2016-05-06 18:40:30 -07001170 CreateOfferWithOneAudioStream();
1171 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergfd8be342016-05-14 19:44:11 -07001172 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001173 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1174 return answer;
1175 }
1176
1177 const std::string& GetFirstAudioStreamCname(
1178 const SessionDescriptionInterface* desc) {
1179 const cricket::ContentInfo* audio_content =
1180 cricket::GetFirstAudioContent(desc->description());
1181 const cricket::AudioContentDescription* audio_desc =
1182 static_cast<const cricket::AudioContentDescription*>(
1183 audio_content->description);
1184 return audio_desc->streams()[0].cname;
1185 }
1186
deadbeef9a6f4d42017-05-15 19:43:33 -07001187 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1188 rtc::AutoSocketServerThread main_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001189 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001190 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001191 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1192 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1193 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001194 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001195 rtc::scoped_refptr<StreamCollection> reference_collection_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196};
1197
zhihuang29ff8442016-07-27 11:07:25 -07001198// Test that no callbacks on the PeerConnectionObserver are called after the
1199// PeerConnection is closed.
1200TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) {
zhihuang9763d562016-08-05 11:14:50 -07001201 rtc::scoped_refptr<PeerConnectionInterface> pc(
zhihuang29ff8442016-07-27 11:07:25 -07001202 pc_factory_for_test_->CreatePeerConnection(
1203 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr,
1204 nullptr, &observer_));
1205 observer_.SetPeerConnectionInterface(pc.get());
1206 pc->Close();
1207
1208 // No callbacks is expected to be called.
zhihuang81c3a032016-11-17 12:06:24 -08001209 observer_.callback_triggered_ = false;
zhihuang29ff8442016-07-27 11:07:25 -07001210 std::vector<cricket::Candidate> candidates;
1211 pc_factory_for_test_->transport_controller->SignalGatheringState(
1212 cricket::IceGatheringState{});
1213 pc_factory_for_test_->transport_controller->SignalCandidatesGathered(
1214 "", candidates);
1215 pc_factory_for_test_->transport_controller->SignalConnectionState(
1216 cricket::IceConnectionState{});
1217 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved(
1218 candidates);
1219 pc_factory_for_test_->transport_controller->SignalReceiving(false);
zhihuang81c3a032016-11-17 12:06:24 -08001220 EXPECT_FALSE(observer_.callback_triggered_);
zhihuang29ff8442016-07-27 11:07:25 -07001221}
1222
zhihuang8f65cdf2016-05-06 18:40:30 -07001223// Generate different CNAMEs when PeerConnections are created.
1224// The CNAMEs are expected to be generated randomly. It is possible
1225// that the test fails, though the possibility is very low.
1226TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001227 std::unique_ptr<SessionDescriptionInterface> offer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001228 CreateOfferWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001229 std::unique_ptr<SessionDescriptionInterface> offer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001230 CreateOfferWithOneAudioStream();
1231 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1232 GetFirstAudioStreamCname(offer2.get()));
1233}
1234
1235TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001236 std::unique_ptr<SessionDescriptionInterface> answer1 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001237 CreateAnswerWithOneAudioStream();
kwibergfd8be342016-05-14 19:44:11 -07001238 std::unique_ptr<SessionDescriptionInterface> answer2 =
zhihuang8f65cdf2016-05-06 18:40:30 -07001239 CreateAnswerWithOneAudioStream();
1240 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1241 GetFirstAudioStreamCname(answer2.get()));
1242}
1243
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244TEST_F(PeerConnectionInterfaceTest,
1245 CreatePeerConnectionWithDifferentConfigurations) {
1246 CreatePeerConnectionWithDifferentConfigurations();
1247}
1248
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001249TEST_F(PeerConnectionInterfaceTest,
1250 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1251 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1252 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1253 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1254 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1255 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1256 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1257 port_allocator_->candidate_filter());
1258 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1259 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1260}
1261
1262// Test that when a PeerConnection is created with a nonzero candidate pool
1263// size, the pooled PortAllocatorSession is created with all the attributes
1264// in the RTCConfiguration.
1265TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1266 PeerConnectionInterface::RTCConfiguration config;
1267 PeerConnectionInterface::IceServer server;
1268 server.uri = kStunAddressOnly;
1269 config.servers.push_back(server);
1270 config.type = PeerConnectionInterface::kRelay;
1271 config.disable_ipv6 = true;
1272 config.tcp_candidate_policy =
1273 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001274 config.candidate_network_policy =
1275 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001276 config.ice_candidate_pool_size = 1;
1277 CreatePeerConnection(config, nullptr);
1278
1279 const cricket::FakePortAllocatorSession* session =
1280 static_cast<const cricket::FakePortAllocatorSession*>(
1281 port_allocator_->GetPooledSession());
1282 ASSERT_NE(nullptr, session);
1283 EXPECT_EQ(1UL, session->stun_servers().size());
1284 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1285 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001286 EXPECT_LT(0U,
1287 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001288}
1289
deadbeefd21eab32017-07-26 16:50:11 -07001290// Test that network-related RTCConfiguration members are applied to the
1291// PortAllocator when CreatePeerConnection is called. Specifically:
1292// - disable_ipv6_on_wifi
1293// - max_ipv6_networks
1294// - tcp_candidate_policy
1295// - candidate_network_policy
1296// - prune_turn_ports
1297//
1298// Note that the candidate filter (RTCConfiguration::type) is already tested
1299// above.
1300TEST_F(PeerConnectionInterfaceTest,
1301 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1302 // Create fake port allocator.
1303 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1304 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1305 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1306
1307 // Create RTCConfiguration with some network-related fields relevant to
1308 // PortAllocator populated.
1309 PeerConnectionInterface::RTCConfiguration config;
1310 config.disable_ipv6_on_wifi = true;
1311 config.max_ipv6_networks = 10;
1312 config.tcp_candidate_policy =
1313 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1314 config.candidate_network_policy =
1315 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1316 config.prune_turn_ports = true;
1317
1318 // Create the PC factory and PC with the above config.
1319 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1320 webrtc::CreatePeerConnectionFactory(
1321 rtc::Thread::Current(), rtc::Thread::Current(),
1322 rtc::Thread::Current(), nullptr, nullptr, nullptr));
1323 rtc::scoped_refptr<PeerConnectionInterface> pc(
1324 pc_factory->CreatePeerConnection(
1325 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1326
1327 // Now validate that the config fields set above were applied to the
1328 // PortAllocator, as flags or otherwise.
1329 EXPECT_FALSE(raw_port_allocator->flags() &
1330 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1331 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1332 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1333 EXPECT_TRUE(raw_port_allocator->flags() &
1334 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1335 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1336}
1337
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001338// Test that the PeerConnection initializes the port allocator passed into it,
1339// and on the correct thread.
1340TEST_F(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001341 CreatePeerConnectionInitializesPortAllocatorOnNetworkThread) {
tommie7251592017-07-14 14:44:46 -07001342 std::unique_ptr<rtc::Thread> network_thread(
1343 rtc::Thread::CreateWithSocketServer());
1344 network_thread->Start();
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001345 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1346 webrtc::CreatePeerConnectionFactory(
tommie7251592017-07-14 14:44:46 -07001347 network_thread.get(), rtc::Thread::Current(), rtc::Thread::Current(),
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001348 nullptr, nullptr, nullptr));
1349 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
tommie7251592017-07-14 14:44:46 -07001350 new cricket::FakePortAllocator(network_thread.get(), nullptr));
Taylor Brandstetterf8e65772016-06-27 17:20:15 -07001351 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1352 PeerConnectionInterface::RTCConfiguration config;
1353 rtc::scoped_refptr<PeerConnectionInterface> pc(
1354 pc_factory->CreatePeerConnection(
1355 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1356 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1357 // so all we have to do here is check that it's initialized.
1358 EXPECT_TRUE(raw_port_allocator->initialized());
1359}
1360
deadbeef46c73892016-11-16 19:42:04 -08001361// Check that GetConfiguration returns the configuration the PeerConnection was
1362// constructed with, before SetConfiguration is called.
1363TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1364 PeerConnectionInterface::RTCConfiguration config;
1365 config.type = PeerConnectionInterface::kRelay;
1366 CreatePeerConnection(config, nullptr);
1367
1368 PeerConnectionInterface::RTCConfiguration returned_config =
1369 pc_->GetConfiguration();
1370 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1371}
1372
1373// Check that GetConfiguration returns the last configuration passed into
1374// SetConfiguration.
1375TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1376 CreatePeerConnection();
1377
1378 PeerConnectionInterface::RTCConfiguration config;
1379 config.type = PeerConnectionInterface::kRelay;
1380 EXPECT_TRUE(pc_->SetConfiguration(config));
1381
1382 PeerConnectionInterface::RTCConfiguration returned_config =
1383 pc_->GetConfiguration();
1384 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1385}
1386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387TEST_F(PeerConnectionInterfaceTest, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001388 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001389 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 AddVoiceStream(kStreamLabel2);
1391 ASSERT_EQ(2u, pc_->local_streams()->count());
1392
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001393 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001394 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
zhihuang9763d562016-08-05 11:14:50 -07001396 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1397 pc_factory_->CreateAudioTrack(kStreamLabel3,
1398 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001400 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001401 EXPECT_EQ(3u, pc_->local_streams()->count());
1402
1403 // Remove the third stream.
1404 pc_->RemoveStream(pc_->local_streams()->at(2));
1405 EXPECT_EQ(2u, pc_->local_streams()->count());
1406
1407 // Remove the second stream.
1408 pc_->RemoveStream(pc_->local_streams()->at(1));
1409 EXPECT_EQ(1u, pc_->local_streams()->count());
1410
1411 // Remove the first stream.
1412 pc_->RemoveStream(pc_->local_streams()->at(0));
1413 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414}
1415
deadbeefab9b2d12015-10-14 11:33:11 -07001416// Test that the created offer includes streams we added.
1417TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001418 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001419 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001420 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001421 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001422
1423 const cricket::ContentInfo* audio_content =
1424 cricket::GetFirstAudioContent(offer->description());
1425 const cricket::AudioContentDescription* audio_desc =
1426 static_cast<const cricket::AudioContentDescription*>(
1427 audio_content->description);
1428 EXPECT_TRUE(
1429 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1430
1431 const cricket::ContentInfo* video_content =
1432 cricket::GetFirstVideoContent(offer->description());
1433 const cricket::VideoContentDescription* video_desc =
1434 static_cast<const cricket::VideoContentDescription*>(
1435 video_content->description);
1436 EXPECT_TRUE(
1437 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1438
1439 // Add another stream and ensure the offer includes both the old and new
1440 // streams.
1441 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001442 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001443
1444 audio_content = cricket::GetFirstAudioContent(offer->description());
1445 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1446 audio_content->description);
1447 EXPECT_TRUE(
1448 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1449 EXPECT_TRUE(
1450 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1451
1452 video_content = cricket::GetFirstVideoContent(offer->description());
1453 video_desc = static_cast<const cricket::VideoContentDescription*>(
1454 video_content->description);
1455 EXPECT_TRUE(
1456 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1457 EXPECT_TRUE(
1458 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1459}
1460
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001462 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001463 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 ASSERT_EQ(1u, pc_->local_streams()->count());
1465 pc_->RemoveStream(pc_->local_streams()->at(0));
1466 EXPECT_EQ(0u, pc_->local_streams()->count());
1467}
1468
deadbeefe1f9d832016-01-14 15:35:42 -08001469// Test for AddTrack and RemoveTrack methods.
1470// Tests that the created offer includes tracks we added,
1471// and that the RtpSenders are created correctly.
1472// Also tests that RemoveTrack removes the tracks from subsequent offers.
1473TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001474 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001475 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001476 rtc::scoped_refptr<MediaStreamInterface> stream(
deadbeefe1f9d832016-01-14 15:35:42 -08001477 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1478 std::vector<MediaStreamInterface*> stream_list;
1479 stream_list.push_back(stream.get());
zhihuang9763d562016-08-05 11:14:50 -07001480 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001481 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001482 rtc::scoped_refptr<VideoTrackInterface> video_track(
1483 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001484 "video_track", pc_factory_->CreateVideoSource(
1485 std::unique_ptr<cricket::VideoCapturer>(
1486 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001487 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1488 auto video_sender = pc_->AddTrack(video_track, stream_list);
deadbeefa601f5c2016-06-06 14:27:39 -07001489 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1490 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001491 EXPECT_EQ("audio_track", audio_sender->id());
1492 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001493 EXPECT_EQ(1UL, video_sender->stream_ids().size());
1494 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001495 EXPECT_EQ("video_track", video_sender->id());
1496 EXPECT_EQ(video_track, video_sender->track());
1497
1498 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001499 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001500 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001501
1502 const cricket::ContentInfo* audio_content =
1503 cricket::GetFirstAudioContent(offer->description());
1504 const cricket::AudioContentDescription* audio_desc =
1505 static_cast<const cricket::AudioContentDescription*>(
1506 audio_content->description);
1507 EXPECT_TRUE(
1508 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1509
1510 const cricket::ContentInfo* video_content =
1511 cricket::GetFirstVideoContent(offer->description());
1512 const cricket::VideoContentDescription* video_desc =
1513 static_cast<const cricket::VideoContentDescription*>(
1514 video_content->description);
1515 EXPECT_TRUE(
1516 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1517
1518 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1519
1520 // Now try removing the tracks.
1521 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1522 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1523
1524 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001525 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001526
1527 audio_content = cricket::GetFirstAudioContent(offer->description());
1528 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1529 audio_content->description);
1530 EXPECT_FALSE(
1531 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1532
1533 video_content = cricket::GetFirstVideoContent(offer->description());
1534 video_desc = static_cast<const cricket::VideoContentDescription*>(
1535 video_content->description);
1536 EXPECT_FALSE(
1537 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1538
1539 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1540
1541 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1542 // should return false.
1543 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1544 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1545}
1546
1547// Test creating senders without a stream specified,
1548// expecting a random stream ID to be generated.
1549TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001550 CreatePeerConnectionWithoutDtls();
deadbeefe1f9d832016-01-14 15:35:42 -08001551 // Create a dummy stream, so tracks share a stream label.
zhihuang9763d562016-08-05 11:14:50 -07001552 rtc::scoped_refptr<AudioTrackInterface> audio_track(
deadbeefe1f9d832016-01-14 15:35:42 -08001553 pc_factory_->CreateAudioTrack("audio_track", nullptr));
zhihuang9763d562016-08-05 11:14:50 -07001554 rtc::scoped_refptr<VideoTrackInterface> video_track(
1555 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001556 "video_track", pc_factory_->CreateVideoSource(
1557 std::unique_ptr<cricket::VideoCapturer>(
1558 new cricket::FakeVideoCapturer()))));
deadbeefe1f9d832016-01-14 15:35:42 -08001559 auto audio_sender =
1560 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1561 auto video_sender =
1562 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1563 EXPECT_EQ("audio_track", audio_sender->id());
1564 EXPECT_EQ(audio_track, audio_sender->track());
1565 EXPECT_EQ("video_track", video_sender->id());
1566 EXPECT_EQ(video_track, video_sender->track());
1567 // If the ID is truly a random GUID, it should be infinitely unlikely they
1568 // will be the same.
deadbeefa601f5c2016-06-06 14:27:39 -07001569 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
deadbeefe1f9d832016-01-14 15:35:42 -08001570}
1571
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1573 InitiateCall();
1574 WaitAndVerifyOnAddStream(kStreamLabel1);
1575 VerifyRemoteRtpHeaderExtensions();
1576}
1577
1578TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001579 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001580 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 CreateOfferAsLocalDescription();
1582 std::string offer;
1583 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1584 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1585 WaitAndVerifyOnAddStream(kStreamLabel1);
1586}
1587
1588TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001589 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001590 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591
1592 CreateOfferAsRemoteDescription();
1593 CreateAnswerAsLocalDescription();
1594
1595 WaitAndVerifyOnAddStream(kStreamLabel1);
1596}
1597
1598TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001599 CreatePeerConnectionWithoutDtls();
deadbeefab9b2d12015-10-14 11:33:11 -07001600 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601
1602 CreateOfferAsRemoteDescription();
1603 CreatePrAnswerAsLocalDescription();
1604 CreateAnswerAsLocalDescription();
1605
1606 WaitAndVerifyOnAddStream(kStreamLabel1);
1607}
1608
1609TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1610 InitiateCall();
1611 ASSERT_EQ(1u, pc_->remote_streams()->count());
1612 pc_->RemoveStream(pc_->local_streams()->at(0));
1613 CreateOfferReceiveAnswer();
1614 EXPECT_EQ(0u, pc_->remote_streams()->count());
deadbeefab9b2d12015-10-14 11:33:11 -07001615 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 CreateOfferReceiveAnswer();
1617}
1618
1619// Tests that after negotiating an audio only call, the respondent can perform a
1620// renegotiation that removes the audio stream.
1621TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001622 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 AddVoiceStream(kStreamLabel1);
1624 CreateOfferAsRemoteDescription();
1625 CreateAnswerAsLocalDescription();
1626
1627 ASSERT_EQ(1u, pc_->remote_streams()->count());
1628 pc_->RemoveStream(pc_->local_streams()->at(0));
1629 CreateOfferReceiveAnswer();
1630 EXPECT_EQ(0u, pc_->remote_streams()->count());
1631}
1632
1633// Test that candidates are generated and that we can parse our own candidates.
1634TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001635 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636
1637 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1638 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001639 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefab9b2d12015-10-14 11:33:11 -07001640 AddVideoStream(kStreamLabel1);
deadbeefc80741f2015-10-22 13:14:45 -07001641 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001642 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643
1644 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001645 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001646 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001647 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648
1649 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1650 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1651
1652 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1653}
1654
deadbeefab9b2d12015-10-14 11:33:11 -07001655// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656// not unique.
1657TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001658 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001660 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001661 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001662 EXPECT_TRUE(offer);
1663 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664
1665 // Create a local stream with audio&video tracks having same label.
1666 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1667
1668 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001669 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670
1671 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001672 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001673 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674}
1675
1676// Test that we will get different SSRCs for each tracks in the offer and answer
1677// we created.
1678TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001679 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 // Create a local stream with audio&video tracks having different labels.
1681 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1682
1683 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001684 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001685 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 int audio_ssrc = 0;
1687 int video_ssrc = 0;
1688 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1689 &audio_ssrc));
1690 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1691 &video_ssrc));
1692 EXPECT_NE(audio_ssrc, video_ssrc);
1693
1694 // Test CreateAnswer
1695 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
kwibergd1fe2812016-04-27 06:47:29 -07001696 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001697 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 audio_ssrc = 0;
1699 video_ssrc = 0;
1700 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1701 &audio_ssrc));
1702 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1703 &video_ssrc));
1704 EXPECT_NE(audio_ssrc, video_ssrc);
1705}
1706
deadbeefeb459812015-12-15 19:24:43 -08001707// Test that it's possible to call AddTrack on a MediaStream after adding
1708// the stream to a PeerConnection.
1709// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1710TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001711 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001712 // Create audio stream and add to PeerConnection.
1713 AddVoiceStream(kStreamLabel1);
1714 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1715
1716 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001717 rtc::scoped_refptr<VideoTrackInterface> video_track(
1718 pc_factory_->CreateVideoTrack(
deadbeef112b2e92017-02-10 20:13:37 -08001719 "video_label", pc_factory_->CreateVideoSource(
1720 std::unique_ptr<cricket::VideoCapturer>(
1721 new cricket::FakeVideoCapturer()))));
deadbeefeb459812015-12-15 19:24:43 -08001722 stream->AddTrack(video_track.get());
1723
kwibergd1fe2812016-04-27 06:47:29 -07001724 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001725 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001726
1727 const cricket::MediaContentDescription* video_desc =
1728 cricket::GetFirstVideoContentDescription(offer->description());
1729 EXPECT_TRUE(video_desc != nullptr);
1730}
1731
1732// Test that it's possible to call RemoveTrack on a MediaStream after adding
1733// the stream to a PeerConnection.
1734// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1735TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001736 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001737 // Create audio/video stream and add to PeerConnection.
1738 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1739 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1740
1741 // Remove the video track.
1742 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1743
kwibergd1fe2812016-04-27 06:47:29 -07001744 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001745 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001746
1747 const cricket::MediaContentDescription* video_desc =
1748 cricket::GetFirstVideoContentDescription(offer->description());
1749 EXPECT_TRUE(video_desc == nullptr);
1750}
1751
deadbeef1dcb1642017-03-29 21:08:16 -07001752// Verify that CreateDtmfSender only succeeds if called with a valid local
1753// track. Other aspects of DtmfSenders are tested in
1754// peerconnection_integrationtest.cc.
1755TEST_F(PeerConnectionInterfaceTest, CreateDtmfSenderWithInvalidParams) {
1756 CreatePeerConnection();
1757 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1758 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(nullptr));
1759 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
1760 pc_factory_->CreateAudioTrack("dummy_track", nullptr));
1761 EXPECT_EQ(nullptr, pc_->CreateDtmfSender(non_localtrack));
1762}
1763
deadbeefbd7d8f72015-12-18 16:58:44 -08001764// Test creating a sender with a stream ID, and ensure the ID is populated
1765// in the offer.
1766TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001767 CreatePeerConnectionWithoutDtls();
deadbeefbd7d8f72015-12-18 16:58:44 -08001768 pc_->CreateSender("video", kStreamLabel1);
1769
kwibergd1fe2812016-04-27 06:47:29 -07001770 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001771 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001772
1773 const cricket::MediaContentDescription* video_desc =
1774 cricket::GetFirstVideoContentDescription(offer->description());
1775 ASSERT_TRUE(video_desc != nullptr);
1776 ASSERT_EQ(1u, video_desc->streams().size());
1777 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1778}
1779
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780// Test that we can specify a certain track that we want statistics about.
1781TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1782 InitiateCall();
1783 ASSERT_LT(0u, pc_->remote_streams()->count());
1784 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001785 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1787 EXPECT_TRUE(DoGetStats(remote_audio));
1788
1789 // Remove the stream. Since we are sending to our selves the local
1790 // and the remote stream is the same.
1791 pc_->RemoveStream(pc_->local_streams()->at(0));
1792 // Do a re-negotiation.
1793 CreateOfferReceiveAnswer();
1794
1795 ASSERT_EQ(0u, pc_->remote_streams()->count());
1796
1797 // Test that we still can get statistics for the old track. Even if it is not
1798 // sent any longer.
1799 EXPECT_TRUE(DoGetStats(remote_audio));
1800}
1801
1802// Test that we can get stats on a video track.
1803TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1804 InitiateCall();
1805 ASSERT_LT(0u, pc_->remote_streams()->count());
1806 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
zhihuang9763d562016-08-05 11:14:50 -07001807 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1809 EXPECT_TRUE(DoGetStats(remote_video));
1810}
1811
1812// Test that we don't get statistics for an invalid track.
zhihuange9e94c32016-11-04 11:38:15 -07001813TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001815 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 pc_factory_->CreateAudioTrack("unknown track", NULL));
1817 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1818}
1819
1820// This test setup two RTP data channels in loop back.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 FakeConstraints constraints;
1823 constraints.SetAllowRtpDataChannels();
1824 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001825 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001827 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 pc_->CreateDataChannel("test2", NULL);
1829 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001830 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001832 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 new MockDataChannelObserver(data2));
1834
1835 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1836 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1837 std::string data_to_send1 = "testing testing";
1838 std::string data_to_send2 = "testing something else";
1839 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1840
1841 CreateOfferReceiveAnswer();
1842 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1843 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1844
1845 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1846 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1847 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1848 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1849
1850 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1851 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1852
1853 data1->Close();
1854 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1855 CreateOfferReceiveAnswer();
1856 EXPECT_FALSE(observer1->IsOpen());
1857 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1858 EXPECT_TRUE(observer2->IsOpen());
1859
1860 data_to_send2 = "testing something else again";
1861 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1862
1863 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1864}
1865
1866// This test verifies that sendnig binary data over RTP data channels should
1867// fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 FakeConstraints constraints;
1870 constraints.SetAllowRtpDataChannels();
1871 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001872 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001874 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 pc_->CreateDataChannel("test2", NULL);
1876 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001877 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001879 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 new MockDataChannelObserver(data2));
1881
1882 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1883 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1884
1885 CreateOfferReceiveAnswer();
1886 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1887 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1888
1889 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1890 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1891
jbaucheec21bd2016-03-20 06:15:43 -07001892 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1894}
1895
1896// This test setup a RTP data channels in loop back and test that a channel is
1897// opened even if the remote end answer with a zero SSRC.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 FakeConstraints constraints;
1900 constraints.SetAllowRtpDataChannels();
1901 CreatePeerConnection(&constraints);
zhihuang9763d562016-08-05 11:14:50 -07001902 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001904 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 new MockDataChannelObserver(data1));
1906
1907 CreateOfferReceiveAnswerWithoutSsrc();
1908
1909 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1910
1911 data1->Close();
1912 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1913 CreateOfferReceiveAnswerWithoutSsrc();
1914 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1915 EXPECT_FALSE(observer1->IsOpen());
1916}
1917
1918// This test that if a data channel is added in an answer a receive only channel
1919// channel is created.
1920TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1921 FakeConstraints constraints;
1922 constraints.SetAllowRtpDataChannels();
1923 CreatePeerConnection(&constraints);
1924
1925 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07001926 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 pc_->CreateDataChannel(offer_label, NULL);
1928
1929 CreateOfferAsLocalDescription();
1930
1931 // Replace the data channel label in the offer and apply it as an answer.
1932 std::string receive_label = "answer_channel";
1933 std::string sdp;
1934 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001935 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936 receive_label.c_str(), receive_label.length(),
1937 &sdp);
1938 CreateAnswerAsRemoteDescription(sdp);
1939
1940 // Verify that a new incoming data channel has been created and that
1941 // it is open but can't we written to.
1942 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1943 DataChannelInterface* received_channel = observer_.last_datachannel_;
1944 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1945 EXPECT_EQ(receive_label, received_channel->label());
1946 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1947
1948 // Verify that the channel we initially offered has been rejected.
1949 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1950
1951 // Do another offer / answer exchange and verify that the data channel is
1952 // opened.
1953 CreateOfferReceiveAnswer();
1954 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1955 kTimeout);
1956}
1957
1958// This test that no data channel is returned if a reliable channel is
1959// requested.
1960// TODO(perkj): Remove this test once reliable channels are implemented.
1961TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1962 FakeConstraints constraints;
1963 constraints.SetAllowRtpDataChannels();
1964 CreatePeerConnection(&constraints);
1965
1966 std::string label = "test";
1967 webrtc::DataChannelInit config;
1968 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07001969 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 pc_->CreateDataChannel(label, &config);
1971 EXPECT_TRUE(channel == NULL);
1972}
1973
deadbeefab9b2d12015-10-14 11:33:11 -07001974// Verifies that duplicated label is not allowed for RTP data channel.
1975TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1976 FakeConstraints constraints;
1977 constraints.SetAllowRtpDataChannels();
1978 CreatePeerConnection(&constraints);
1979
1980 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07001981 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001982 pc_->CreateDataChannel(label, nullptr);
1983 EXPECT_NE(channel, nullptr);
1984
zhihuang9763d562016-08-05 11:14:50 -07001985 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07001986 pc_->CreateDataChannel(label, nullptr);
1987 EXPECT_EQ(dup_channel, nullptr);
1988}
1989
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990// This tests that a SCTP data channel is returned using different
1991// DataChannelInit configurations.
1992TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1993 FakeConstraints constraints;
1994 constraints.SetAllowDtlsSctpDataChannels();
1995 CreatePeerConnection(&constraints);
1996
1997 webrtc::DataChannelInit config;
1998
zhihuang9763d562016-08-05 11:14:50 -07001999 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 pc_->CreateDataChannel("1", &config);
2001 EXPECT_TRUE(channel != NULL);
2002 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002003 EXPECT_TRUE(observer_.renegotiation_needed_);
2004 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005
2006 config.ordered = false;
2007 channel = pc_->CreateDataChannel("2", &config);
2008 EXPECT_TRUE(channel != NULL);
2009 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002010 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011
2012 config.ordered = true;
2013 config.maxRetransmits = 0;
2014 channel = pc_->CreateDataChannel("3", &config);
2015 EXPECT_TRUE(channel != NULL);
2016 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002017 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018
2019 config.maxRetransmits = -1;
2020 config.maxRetransmitTime = 0;
2021 channel = pc_->CreateDataChannel("4", &config);
2022 EXPECT_TRUE(channel != NULL);
2023 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002024 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025}
2026
2027// This tests that no data channel is returned if both maxRetransmits and
2028// maxRetransmitTime are set for SCTP data channels.
2029TEST_F(PeerConnectionInterfaceTest,
2030 CreateSctpDataChannelShouldFailForInvalidConfig) {
2031 FakeConstraints constraints;
2032 constraints.SetAllowDtlsSctpDataChannels();
2033 CreatePeerConnection(&constraints);
2034
2035 std::string label = "test";
2036 webrtc::DataChannelInit config;
2037 config.maxRetransmits = 0;
2038 config.maxRetransmitTime = 0;
2039
zhihuang9763d562016-08-05 11:14:50 -07002040 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 pc_->CreateDataChannel(label, &config);
2042 EXPECT_TRUE(channel == NULL);
2043}
2044
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045// The test verifies that creating a SCTP data channel with an id already in use
2046// or out of range should fail.
2047TEST_F(PeerConnectionInterfaceTest,
2048 CreateSctpDataChannelWithInvalidIdShouldFail) {
2049 FakeConstraints constraints;
2050 constraints.SetAllowDtlsSctpDataChannels();
2051 CreatePeerConnection(&constraints);
2052
2053 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002054 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002056 config.id = 1;
2057 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 EXPECT_TRUE(channel != NULL);
2059 EXPECT_EQ(1, channel->id());
2060
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 channel = pc_->CreateDataChannel("x", &config);
2062 EXPECT_TRUE(channel == NULL);
2063
2064 config.id = cricket::kMaxSctpSid;
2065 channel = pc_->CreateDataChannel("max", &config);
2066 EXPECT_TRUE(channel != NULL);
2067 EXPECT_EQ(config.id, channel->id());
2068
2069 config.id = cricket::kMaxSctpSid + 1;
2070 channel = pc_->CreateDataChannel("x", &config);
2071 EXPECT_TRUE(channel == NULL);
2072}
2073
deadbeefab9b2d12015-10-14 11:33:11 -07002074// Verifies that duplicated label is allowed for SCTP data channel.
2075TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
2076 FakeConstraints constraints;
2077 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2078 true);
2079 CreatePeerConnection(&constraints);
2080
2081 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002082 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002083 pc_->CreateDataChannel(label, nullptr);
2084 EXPECT_NE(channel, nullptr);
2085
zhihuang9763d562016-08-05 11:14:50 -07002086 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002087 pc_->CreateDataChannel(label, nullptr);
2088 EXPECT_NE(dup_channel, nullptr);
2089}
2090
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002091// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2092// DataChannel.
2093TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
2094 FakeConstraints constraints;
2095 constraints.SetAllowRtpDataChannels();
2096 CreatePeerConnection(&constraints);
2097
zhihuang9763d562016-08-05 11:14:50 -07002098 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002099 pc_->CreateDataChannel("test1", NULL);
2100 EXPECT_TRUE(observer_.renegotiation_needed_);
2101 observer_.renegotiation_needed_ = false;
2102
zhihuang9763d562016-08-05 11:14:50 -07002103 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002104 pc_->CreateDataChannel("test2", NULL);
2105 EXPECT_TRUE(observer_.renegotiation_needed_);
2106}
2107
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108// This test that a data channel closes when a PeerConnection is deleted/closed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 FakeConstraints constraints;
2111 constraints.SetAllowRtpDataChannels();
2112 CreatePeerConnection(&constraints);
2113
zhihuang9763d562016-08-05 11:14:50 -07002114 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002116 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 pc_->CreateDataChannel("test2", NULL);
2118 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002119 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002121 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 new MockDataChannelObserver(data2));
2123
2124 CreateOfferReceiveAnswer();
2125 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2126 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2127
2128 ReleasePeerConnection();
2129 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2130 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2131}
2132
2133// This test that data channels can be rejected in an answer.
2134TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
2135 FakeConstraints constraints;
2136 constraints.SetAllowRtpDataChannels();
2137 CreatePeerConnection(&constraints);
2138
zhihuang9763d562016-08-05 11:14:50 -07002139 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 pc_->CreateDataChannel("offer_channel", NULL));
2141
2142 CreateOfferAsLocalDescription();
2143
2144 // Create an answer where the m-line for data channels are rejected.
2145 std::string sdp;
2146 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2147 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
2148 SessionDescriptionInterface::kAnswer);
2149 EXPECT_TRUE(answer->Initialize(sdp, NULL));
2150 cricket::ContentInfo* data_info =
2151 answer->description()->GetContentByName("data");
2152 data_info->rejected = true;
2153
2154 DoSetRemoteDescription(answer);
2155 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2156}
2157
2158// Test that we can create a session description from an SDP string from
2159// FireFox, use it as a remote session description, generate an answer and use
2160// the answer as a local description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002161TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 FakeConstraints constraints;
2163 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2164 true);
2165 CreatePeerConnection(&constraints);
2166 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2167 SessionDescriptionInterface* desc =
2168 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002169 webrtc::kFireFoxSdpOffer, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2171 CreateAnswerAsLocalDescription();
2172 ASSERT_TRUE(pc_->local_description() != NULL);
2173 ASSERT_TRUE(pc_->remote_description() != NULL);
2174
2175 const cricket::ContentInfo* content =
2176 cricket::GetFirstAudioContent(pc_->local_description()->description());
2177 ASSERT_TRUE(content != NULL);
2178 EXPECT_FALSE(content->rejected);
2179
2180 content =
2181 cricket::GetFirstVideoContent(pc_->local_description()->description());
2182 ASSERT_TRUE(content != NULL);
2183 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002184#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 content =
2186 cricket::GetFirstDataContent(pc_->local_description()->description());
2187 ASSERT_TRUE(content != NULL);
2188 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002189#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190}
2191
deadbeef8662f942017-01-20 21:20:51 -08002192// Test that an offer can be received which offers DTLS with SDES fallback.
2193// Regression test for issue:
2194// https://bugs.chromium.org/p/webrtc/issues/detail?id=6972
2195TEST_F(PeerConnectionInterfaceTest, ReceiveDtlsSdesFallbackOffer) {
2196 FakeConstraints constraints;
2197 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2198 true);
2199 CreatePeerConnection(&constraints);
2200 // Wait for fake certificate to be generated. Previously, this is what caused
2201 // the "a=crypto" lines to be rejected.
2202 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2203 ASSERT_NE(nullptr, fake_certificate_generator_);
2204 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2205 kTimeout);
2206 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
2207 SessionDescriptionInterface::kOffer, kDtlsSdesFallbackSdp, nullptr);
2208 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2209 CreateAnswerAsLocalDescription();
2210}
2211
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212// Test that we can create an audio only offer and receive an answer with a
2213// limited set of audio codecs and receive an updated offer with more audio
2214// codecs, where the added codecs are not supported.
2215TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002216 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 AddVoiceStream("audio_label");
2218 CreateOfferAsLocalDescription();
2219
2220 SessionDescriptionInterface* answer =
2221 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
jbauchfabe2c92015-07-16 13:43:14 -07002222 webrtc::kAudioSdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 EXPECT_TRUE(DoSetSessionDescription(answer, false));
2224
2225 SessionDescriptionInterface* updated_offer =
2226 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07002227 webrtc::kAudioSdpWithUnsupportedCodecs,
2228 nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
2230 CreateAnswerAsLocalDescription();
2231}
2232
deadbeefc80741f2015-10-22 13:14:45 -07002233// Test that if we're receiving (but not sending) a track, subsequent offers
2234// will have m-lines with a=recvonly.
2235TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2236 FakeConstraints constraints;
2237 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2238 true);
2239 CreatePeerConnection(&constraints);
2240 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2241 CreateAnswerAsLocalDescription();
2242
2243 // At this point we should be receiving stream 1, but not sending anything.
2244 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002245 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002246 DoCreateOffer(&offer, nullptr);
2247
2248 const cricket::ContentInfo* video_content =
2249 cricket::GetFirstVideoContent(offer->description());
2250 const cricket::VideoContentDescription* video_desc =
2251 static_cast<const cricket::VideoContentDescription*>(
2252 video_content->description);
2253 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
2254
2255 const cricket::ContentInfo* audio_content =
2256 cricket::GetFirstAudioContent(offer->description());
2257 const cricket::AudioContentDescription* audio_desc =
2258 static_cast<const cricket::AudioContentDescription*>(
2259 audio_content->description);
2260 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
2261}
2262
2263// Test that if we're receiving (but not sending) a track, and the
2264// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2265// false, the generated m-lines will be a=inactive.
2266TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2267 FakeConstraints constraints;
2268 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2269 true);
2270 CreatePeerConnection(&constraints);
2271 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2272 CreateAnswerAsLocalDescription();
2273
2274 // At this point we should be receiving stream 1, but not sending anything.
2275 // A new offer would be recvonly, but we'll set the "no receive" constraints
2276 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002277 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002278 FakeConstraints offer_constraints;
2279 offer_constraints.AddMandatory(
2280 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2281 offer_constraints.AddMandatory(
2282 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2283 DoCreateOffer(&offer, &offer_constraints);
2284
2285 const cricket::ContentInfo* video_content =
2286 cricket::GetFirstVideoContent(offer->description());
2287 const cricket::VideoContentDescription* video_desc =
2288 static_cast<const cricket::VideoContentDescription*>(
2289 video_content->description);
2290 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
2291
2292 const cricket::ContentInfo* audio_content =
2293 cricket::GetFirstAudioContent(offer->description());
2294 const cricket::AudioContentDescription* audio_desc =
2295 static_cast<const cricket::AudioContentDescription*>(
2296 audio_content->description);
2297 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
2298}
2299
deadbeef653b8e02015-11-11 12:55:10 -08002300// Test that we can use SetConfiguration to change the ICE servers of the
2301// PortAllocator.
2302TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2303 CreatePeerConnection();
2304
2305 PeerConnectionInterface::RTCConfiguration config;
2306 PeerConnectionInterface::IceServer server;
2307 server.uri = "stun:test_hostname";
2308 config.servers.push_back(server);
2309 EXPECT_TRUE(pc_->SetConfiguration(config));
2310
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002311 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2312 EXPECT_EQ("test_hostname",
2313 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002314}
2315
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002316TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2317 CreatePeerConnection();
2318 PeerConnectionInterface::RTCConfiguration config;
2319 config.type = PeerConnectionInterface::kRelay;
2320 EXPECT_TRUE(pc_->SetConfiguration(config));
2321 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2322}
2323
deadbeef293e9262017-01-11 12:28:30 -08002324TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
2325 PeerConnectionInterface::RTCConfiguration config;
2326 config.prune_turn_ports = false;
2327 CreatePeerConnection(config, nullptr);
2328 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2329
2330 config.prune_turn_ports = true;
2331 EXPECT_TRUE(pc_->SetConfiguration(config));
2332 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2333}
2334
skvladd1f5fda2017-02-03 16:54:05 -08002335// Test that the ice check interval can be changed. This does not verify that
2336// the setting makes it all the way to P2PTransportChannel, as that would
2337// require a very complex set of mocks.
2338TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
2339 PeerConnectionInterface::RTCConfiguration config;
2340 config.ice_check_min_interval = rtc::Optional<int>();
2341 CreatePeerConnection(config, nullptr);
2342 config.ice_check_min_interval = rtc::Optional<int>(100);
2343 EXPECT_TRUE(pc_->SetConfiguration(config));
2344 PeerConnectionInterface::RTCConfiguration new_config =
2345 pc_->GetConfiguration();
2346 EXPECT_EQ(new_config.ice_check_min_interval, rtc::Optional<int>(100));
2347}
2348
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002349// Test that when SetConfiguration changes both the pool size and other
2350// attributes, the pooled session is created with the updated attributes.
2351TEST_F(PeerConnectionInterfaceTest,
2352 SetConfigurationCreatesPooledSessionCorrectly) {
2353 CreatePeerConnection();
2354 PeerConnectionInterface::RTCConfiguration config;
2355 config.ice_candidate_pool_size = 1;
2356 PeerConnectionInterface::IceServer server;
2357 server.uri = kStunAddressOnly;
2358 config.servers.push_back(server);
2359 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002360 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002361
2362 const cricket::FakePortAllocatorSession* session =
2363 static_cast<const cricket::FakePortAllocatorSession*>(
2364 port_allocator_->GetPooledSession());
2365 ASSERT_NE(nullptr, session);
2366 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002367}
2368
deadbeef293e9262017-01-11 12:28:30 -08002369// Test that after SetLocalDescription, changing the pool size is not allowed,
2370// and an invalid modification error is returned.
deadbeef6de92f92016-12-12 18:49:32 -08002371TEST_F(PeerConnectionInterfaceTest,
2372 CantChangePoolSizeAfterSetLocalDescription) {
2373 CreatePeerConnection();
2374 // Start by setting a size of 1.
2375 PeerConnectionInterface::RTCConfiguration config;
2376 config.ice_candidate_pool_size = 1;
2377 EXPECT_TRUE(pc_->SetConfiguration(config));
2378
2379 // Set remote offer; can still change pool size at this point.
2380 CreateOfferAsRemoteDescription();
2381 config.ice_candidate_pool_size = 2;
2382 EXPECT_TRUE(pc_->SetConfiguration(config));
2383
2384 // Set local answer; now it's too late.
2385 CreateAnswerAsLocalDescription();
2386 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002387 RTCError error;
2388 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2389 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2390}
2391
deadbeef42a42632017-03-10 15:18:00 -08002392// Test that after setting an answer, extra pooled sessions are discarded. The
2393// ICE candidate pool is only intended to be used for the first offer/answer.
2394TEST_F(PeerConnectionInterfaceTest,
2395 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2396 CreatePeerConnection();
2397
2398 // Set a larger-than-necessary size.
2399 PeerConnectionInterface::RTCConfiguration config;
2400 config.ice_candidate_pool_size = 4;
2401 EXPECT_TRUE(pc_->SetConfiguration(config));
2402
2403 // Do offer/answer.
2404 CreateOfferAsRemoteDescription();
2405 CreateAnswerAsLocalDescription();
2406
2407 // Expect no pooled sessions to be left.
2408 const cricket::PortAllocatorSession* session =
2409 port_allocator_->GetPooledSession();
2410 EXPECT_EQ(nullptr, session);
2411}
2412
2413// After Close is called, pooled candidates should be discarded so as to not
2414// waste network resources.
2415TEST_F(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
2416 CreatePeerConnection();
2417
2418 PeerConnectionInterface::RTCConfiguration config;
2419 config.ice_candidate_pool_size = 3;
2420 EXPECT_TRUE(pc_->SetConfiguration(config));
2421 pc_->Close();
2422
2423 // Expect no pooled sessions to be left.
2424 const cricket::PortAllocatorSession* session =
2425 port_allocator_->GetPooledSession();
2426 EXPECT_EQ(nullptr, session);
2427}
2428
deadbeef293e9262017-01-11 12:28:30 -08002429// Test that SetConfiguration returns an invalid modification error if
2430// modifying a field in the configuration that isn't allowed to be modified.
2431TEST_F(PeerConnectionInterfaceTest,
2432 SetConfigurationReturnsInvalidModificationError) {
2433 PeerConnectionInterface::RTCConfiguration config;
2434 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2435 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2436 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2437 CreatePeerConnection(config, nullptr);
2438
2439 PeerConnectionInterface::RTCConfiguration modified_config = config;
2440 modified_config.bundle_policy =
2441 PeerConnectionInterface::kBundlePolicyMaxBundle;
2442 RTCError error;
2443 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2444 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2445
2446 modified_config = config;
2447 modified_config.rtcp_mux_policy =
2448 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2449 error.set_type(RTCErrorType::NONE);
2450 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2451 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2452
2453 modified_config = config;
2454 modified_config.continual_gathering_policy =
2455 PeerConnectionInterface::GATHER_CONTINUALLY;
2456 error.set_type(RTCErrorType::NONE);
2457 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2458 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2459}
2460
2461// Test that SetConfiguration returns a range error if the candidate pool size
2462// is negative or larger than allowed by the spec.
2463TEST_F(PeerConnectionInterfaceTest,
2464 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2465 PeerConnectionInterface::RTCConfiguration config;
2466 CreatePeerConnection(config, nullptr);
2467
2468 config.ice_candidate_pool_size = -1;
2469 RTCError error;
2470 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2471 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2472
2473 config.ice_candidate_pool_size = INT_MAX;
2474 error.set_type(RTCErrorType::NONE);
2475 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2476 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2477}
2478
2479// Test that SetConfiguration returns a syntax error if parsing an ICE server
2480// URL failed.
2481TEST_F(PeerConnectionInterfaceTest,
2482 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2483 PeerConnectionInterface::RTCConfiguration config;
2484 CreatePeerConnection(config, nullptr);
2485
2486 PeerConnectionInterface::IceServer bad_server;
2487 bad_server.uri = "stunn:www.example.com";
2488 config.servers.push_back(bad_server);
2489 RTCError error;
2490 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2491 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2492}
2493
2494// Test that SetConfiguration returns an invalid parameter error if a TURN
2495// IceServer is missing a username or password.
2496TEST_F(PeerConnectionInterfaceTest,
2497 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2498 PeerConnectionInterface::RTCConfiguration config;
2499 CreatePeerConnection(config, nullptr);
2500
2501 PeerConnectionInterface::IceServer bad_server;
2502 bad_server.uri = "turn:www.example.com";
2503 // Missing password.
2504 bad_server.username = "foo";
2505 config.servers.push_back(bad_server);
2506 RTCError error;
2507 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2508 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002509}
2510
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511// Test that PeerConnection::Close changes the states to closed and all remote
2512// tracks change state to ended.
2513TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2514 // Initialize a PeerConnection and negotiate local and remote session
2515 // description.
2516 InitiateCall();
2517 ASSERT_EQ(1u, pc_->local_streams()->count());
2518 ASSERT_EQ(1u, pc_->remote_streams()->count());
2519
2520 pc_->Close();
2521
2522 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2523 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2524 pc_->ice_connection_state());
2525 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2526 pc_->ice_gathering_state());
2527
2528 EXPECT_EQ(1u, pc_->local_streams()->count());
2529 EXPECT_EQ(1u, pc_->remote_streams()->count());
2530
zhihuang9763d562016-08-05 11:14:50 -07002531 rtc::scoped_refptr<MediaStreamInterface> remote_stream =
2532 pc_->remote_streams()->at(0);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002533 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002534 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002535 remote_stream->GetAudioTracks()[0]->state(), kTimeout);
2536 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2537 remote_stream->GetVideoTracks()[0]->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538}
2539
2540// Test that PeerConnection methods fails gracefully after
2541// PeerConnection::Close has been called.
2542TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002543 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2545 CreateOfferAsRemoteDescription();
2546 CreateAnswerAsLocalDescription();
2547
2548 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002549 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 pc_->local_streams()->at(0);
2551
2552 pc_->Close();
2553
2554 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002555 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556
2557 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002558 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00002560 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561
2562 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2563
2564 EXPECT_TRUE(pc_->local_description() != NULL);
2565 EXPECT_TRUE(pc_->remote_description() != NULL);
2566
kwibergd1fe2812016-04-27 06:47:29 -07002567 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07002568 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002569 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07002570 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571
2572 std::string sdp;
2573 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2574 SessionDescriptionInterface* remote_offer =
2575 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2576 sdp, NULL);
2577 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
2578
2579 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2580 SessionDescriptionInterface* local_offer =
2581 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2582 sdp, NULL);
2583 EXPECT_FALSE(DoSetLocalDescription(local_offer));
2584}
2585
2586// Test that GetStats can still be called after PeerConnection::Close.
2587TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
2588 InitiateCall();
2589 pc_->Close();
2590 DoGetStats(NULL);
2591}
deadbeefab9b2d12015-10-14 11:33:11 -07002592
2593// NOTE: The series of tests below come from what used to be
2594// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2595// setting a remote or local description has the expected effects.
2596
2597// This test verifies that the remote MediaStreams corresponding to a received
2598// SDP string is created. In this test the two separate MediaStreams are
2599// signaled.
2600TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2601 FakeConstraints constraints;
2602 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2603 true);
2604 CreatePeerConnection(&constraints);
2605 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2606
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002607 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002608 EXPECT_TRUE(
2609 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2610 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2611 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2612
2613 // Create a session description based on another SDP with another
2614 // MediaStream.
2615 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
2616
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002617 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002618 EXPECT_TRUE(
2619 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2620}
2621
2622// This test verifies that when remote tracks are added/removed from SDP, the
2623// created remote streams are updated appropriately.
2624TEST_F(PeerConnectionInterfaceTest,
2625 AddRemoveTrackFromExistingRemoteMediaStream) {
2626 FakeConstraints constraints;
2627 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2628 true);
2629 CreatePeerConnection(&constraints);
kwibergd1fe2812016-04-27 06:47:29 -07002630 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002631 CreateSessionDescriptionAndReference(1, 1);
deadbeefab9b2d12015-10-14 11:33:11 -07002632 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
2633 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2634 reference_collection_));
2635
2636 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002637 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002638 CreateSessionDescriptionAndReference(2, 2);
deadbeefab9b2d12015-10-14 11:33:11 -07002639 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
2640 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2641 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002642 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002643 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2644 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002645 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002646 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2647 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002648
2649 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002650 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002651 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002652 MockTrackObserver audio_track_observer(audio_track2);
2653 MockTrackObserver video_track_observer(video_track2);
2654
2655 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2656 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
deadbeefab9b2d12015-10-14 11:33:11 -07002657 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
2658 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2659 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002660 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002661 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002662 audio_track2->state(), kTimeout);
2663 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2664 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002665}
2666
2667// This tests that remote tracks are ended if a local session description is set
2668// that rejects the media content type.
2669TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
2670 FakeConstraints constraints;
2671 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2672 true);
2673 CreatePeerConnection(&constraints);
2674 // First create and set a remote offer, then reject its video content in our
2675 // answer.
2676 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2677 ASSERT_EQ(1u, observer_.remote_streams()->count());
2678 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2679 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2680 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2681
2682 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
2683 remote_stream->GetVideoTracks()[0];
2684 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
2685 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
2686 remote_stream->GetAudioTracks()[0];
2687 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2688
kwibergd1fe2812016-04-27 06:47:29 -07002689 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002690 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002691 cricket::ContentInfo* video_info =
2692 local_answer->description()->GetContentByName("video");
2693 video_info->rejected = true;
2694 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2695 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2696 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2697
2698 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002699 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002700 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002701 video_info = local_offer->description()->GetContentByName("video");
2702 ASSERT_TRUE(video_info != nullptr);
2703 video_info->rejected = true;
2704 cricket::ContentInfo* audio_info =
2705 local_offer->description()->GetContentByName("audio");
2706 ASSERT_TRUE(audio_info != nullptr);
2707 audio_info->rejected = true;
2708 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002709 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002710 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002711 remote_audio->state(), kTimeout);
2712 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2713 remote_video->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002714}
2715
2716// This tests that we won't crash if the remote track has been removed outside
2717// of PeerConnection and then PeerConnection tries to reject the track.
2718TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2719 FakeConstraints constraints;
2720 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2721 true);
2722 CreatePeerConnection(&constraints);
2723 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2724 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2725 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2726 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2727
kwibergd1fe2812016-04-27 06:47:29 -07002728 std::unique_ptr<SessionDescriptionInterface> local_answer(
deadbeefab9b2d12015-10-14 11:33:11 -07002729 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2730 kSdpStringWithStream1, nullptr));
2731 cricket::ContentInfo* video_info =
2732 local_answer->description()->GetContentByName("video");
2733 video_info->rejected = true;
2734 cricket::ContentInfo* audio_info =
2735 local_answer->description()->GetContentByName("audio");
2736 audio_info->rejected = true;
2737 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2738
2739 // No crash is a pass.
2740}
2741
deadbeef5e97fb52015-10-15 12:49:08 -07002742// This tests that if a recvonly remote description is set, no remote streams
2743// will be created, even if the description contains SSRCs/MSIDs.
2744// See: https://code.google.com/p/webrtc/issues/detail?id=5054
2745TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2746 FakeConstraints constraints;
2747 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2748 true);
2749 CreatePeerConnection(&constraints);
2750
2751 std::string recvonly_offer = kSdpStringWithStream1;
2752 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2753 strlen(kRecvonly), &recvonly_offer);
2754 CreateAndSetRemoteOffer(recvonly_offer);
2755
2756 EXPECT_EQ(0u, observer_.remote_streams()->count());
2757}
2758
deadbeefab9b2d12015-10-14 11:33:11 -07002759// This tests that a default MediaStream is created if a remote session
2760// description doesn't contain any streams and no MSID support.
2761// It also tests that the default stream is updated if a video m-line is added
2762// in a subsequent session description.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002763TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002764 FakeConstraints constraints;
2765 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2766 true);
2767 CreatePeerConnection(&constraints);
2768 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2769
2770 ASSERT_EQ(1u, observer_.remote_streams()->count());
2771 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2772
2773 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2774 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2775 EXPECT_EQ("default", remote_stream->label());
2776
2777 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2778 ASSERT_EQ(1u, observer_.remote_streams()->count());
2779 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2780 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002781 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2782 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002783 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2784 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002785 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2786 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002787}
2788
2789// This tests that a default MediaStream is created if a remote session
2790// description doesn't contain any streams and media direction is send only.
2791TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002792 SendOnlySdpWithoutMsidCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002793 FakeConstraints constraints;
2794 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2795 true);
2796 CreatePeerConnection(&constraints);
2797 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2798
2799 ASSERT_EQ(1u, observer_.remote_streams()->count());
2800 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2801
2802 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2803 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2804 EXPECT_EQ("default", remote_stream->label());
2805}
2806
2807// This tests that it won't crash when PeerConnection tries to remove
2808// a remote track that as already been removed from the MediaStream.
2809TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2810 FakeConstraints constraints;
2811 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2812 true);
2813 CreatePeerConnection(&constraints);
2814 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2815 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2816 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2817 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2818
2819 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2820
2821 // No crash is a pass.
2822}
2823
2824// This tests that a default MediaStream is created if the remote session
2825// description doesn't contain any streams and don't contain an indication if
2826// MSID is supported.
2827TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002828 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002829 FakeConstraints constraints;
2830 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2831 true);
2832 CreatePeerConnection(&constraints);
2833 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2834
2835 ASSERT_EQ(1u, observer_.remote_streams()->count());
2836 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2837 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2838 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2839}
2840
2841// This tests that a default MediaStream is not created if the remote session
2842// description doesn't contain any streams but does support MSID.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002843TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07002844 FakeConstraints constraints;
2845 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2846 true);
2847 CreatePeerConnection(&constraints);
2848 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2849 EXPECT_EQ(0u, observer_.remote_streams()->count());
2850}
2851
deadbeefbda7e0b2015-12-08 17:13:40 -08002852// This tests that when setting a new description, the old default tracks are
2853// not destroyed and recreated.
2854// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Stefan Holmer102362b2016-03-18 09:39:07 +01002855TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002856 DefaultTracksNotDestroyedAndRecreated) {
deadbeefbda7e0b2015-12-08 17:13:40 -08002857 FakeConstraints constraints;
2858 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2859 true);
2860 CreatePeerConnection(&constraints);
2861 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2862
2863 ASSERT_EQ(1u, observer_.remote_streams()->count());
2864 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2865 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2866
2867 // Set the track to "disabled", then set a new description and ensure the
2868 // track is still disabled, which ensures it hasn't been recreated.
2869 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2870 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2871 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2872 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2873}
2874
deadbeefab9b2d12015-10-14 11:33:11 -07002875// This tests that a default MediaStream is not created if a remote session
2876// description is updated to not have any MediaStreams.
2877TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2878 FakeConstraints constraints;
2879 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2880 true);
2881 CreatePeerConnection(&constraints);
2882 CreateAndSetRemoteOffer(kSdpStringWithStream1);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002883 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002884 EXPECT_TRUE(
2885 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2886
2887 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2888 EXPECT_EQ(0u, observer_.remote_streams()->count());
2889}
2890
2891// This tests that an RtpSender is created when the local description is set
2892// after adding a local stream.
2893// TODO(deadbeef): This test and the one below it need to be updated when
2894// an RtpSender's lifetime isn't determined by when a local description is set.
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002895TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002896 FakeConstraints constraints;
2897 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2898 true);
2899 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002900
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002901 // Create an offer with 1 stream with 2 tracks of each type.
2902 rtc::scoped_refptr<StreamCollection> stream_collection =
2903 CreateStreamCollection(1, 2);
2904 pc_->AddStream(stream_collection->at(0));
2905 std::unique_ptr<SessionDescriptionInterface> offer;
2906 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2907 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002908
deadbeefab9b2d12015-10-14 11:33:11 -07002909 auto senders = pc_->GetSenders();
2910 EXPECT_EQ(4u, senders.size());
2911 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2912 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2913 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2914 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2915
2916 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002917 pc_->RemoveStream(stream_collection->at(0));
2918 stream_collection = CreateStreamCollection(1, 1);
2919 pc_->AddStream(stream_collection->at(0));
2920 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2921 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2922
deadbeefab9b2d12015-10-14 11:33:11 -07002923 senders = pc_->GetSenders();
2924 EXPECT_EQ(2u, senders.size());
2925 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2926 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2927 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2928 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2929}
2930
2931// This tests that an RtpSender is created when the local description is set
2932// before adding a local stream.
2933TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002934 AddLocalStreamAfterLocalDescriptionChanged) {
deadbeefab9b2d12015-10-14 11:33:11 -07002935 FakeConstraints constraints;
2936 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2937 true);
2938 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002939
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002940 rtc::scoped_refptr<StreamCollection> stream_collection =
2941 CreateStreamCollection(1, 2);
2942 // Add a stream to create the offer, but remove it afterwards.
2943 pc_->AddStream(stream_collection->at(0));
2944 std::unique_ptr<SessionDescriptionInterface> offer;
2945 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2946 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002947
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002948 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002949 auto senders = pc_->GetSenders();
2950 EXPECT_EQ(0u, senders.size());
2951
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002952 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002953 senders = pc_->GetSenders();
2954 EXPECT_EQ(4u, senders.size());
2955 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2956 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2957 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2958 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2959}
2960
2961// This tests that the expected behavior occurs if the SSRC on a local track is
2962// changed when SetLocalDescription is called.
2963TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002964 ChangeSsrcOnTrackInLocalSessionDescription) {
deadbeefab9b2d12015-10-14 11:33:11 -07002965 FakeConstraints constraints;
2966 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2967 true);
2968 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07002969
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002970 rtc::scoped_refptr<StreamCollection> stream_collection =
2971 CreateStreamCollection(2, 1);
2972 pc_->AddStream(stream_collection->at(0));
2973 std::unique_ptr<SessionDescriptionInterface> offer;
2974 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2975 // Grab a copy of the offer before it gets passed into the PC.
2976 std::unique_ptr<JsepSessionDescription> modified_offer(
2977 new JsepSessionDescription(JsepSessionDescription::kOffer));
2978 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
2979 offer->session_version());
2980 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07002981
deadbeefab9b2d12015-10-14 11:33:11 -07002982 auto senders = pc_->GetSenders();
2983 EXPECT_EQ(2u, senders.size());
2984 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2985 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2986
2987 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002988 cricket::MediaContentDescription* desc =
2989 cricket::GetFirstAudioContentDescription(modified_offer->description());
2990 ASSERT_TRUE(desc != NULL);
2991 for (StreamParams& stream : desc->mutable_streams()) {
2992 for (unsigned int& ssrc : stream.ssrcs) {
2993 ++ssrc;
2994 }
2995 }
deadbeefab9b2d12015-10-14 11:33:11 -07002996
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002997 desc =
2998 cricket::GetFirstVideoContentDescription(modified_offer->description());
2999 ASSERT_TRUE(desc != NULL);
3000 for (StreamParams& stream : desc->mutable_streams()) {
3001 for (unsigned int& ssrc : stream.ssrcs) {
3002 ++ssrc;
3003 }
3004 }
3005
3006 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07003007 senders = pc_->GetSenders();
3008 EXPECT_EQ(2u, senders.size());
3009 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3010 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3011 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3012 // changed.
3013}
3014
3015// This tests that the expected behavior occurs if a new session description is
3016// set with the same tracks, but on a different MediaStream.
Stefan Holmer55d6e7c2016-03-17 16:26:40 +01003017TEST_F(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003018 SignalSameTracksInSeparateMediaStream) {
deadbeefab9b2d12015-10-14 11:33:11 -07003019 FakeConstraints constraints;
3020 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3021 true);
3022 CreatePeerConnection(&constraints);
deadbeefab9b2d12015-10-14 11:33:11 -07003023
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003024 rtc::scoped_refptr<StreamCollection> stream_collection =
3025 CreateStreamCollection(2, 1);
3026 pc_->AddStream(stream_collection->at(0));
3027 std::unique_ptr<SessionDescriptionInterface> offer;
3028 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3029 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07003030
deadbeefab9b2d12015-10-14 11:33:11 -07003031 auto senders = pc_->GetSenders();
3032 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003033 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3034 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003035
3036 // Add a new MediaStream but with the same tracks as in the first stream.
3037 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3038 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003039 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3040 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003041 pc_->AddStream(stream_1);
3042
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003043 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3044 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
deadbeefab9b2d12015-10-14 11:33:11 -07003045
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003046 auto new_senders = pc_->GetSenders();
3047 // Should be the same senders as before, but with updated stream id.
3048 // Note that this behavior is subject to change in the future.
3049 // We may decide the PC should ignore existing tracks in AddStream.
3050 EXPECT_EQ(senders, new_senders);
3051 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3052 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003053}
3054
zhihuang81c3a032016-11-17 12:06:24 -08003055// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
3056TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) {
3057 FakeConstraints constraints;
3058 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
3059 true);
3060 CreatePeerConnection(&constraints);
3061 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3062 EXPECT_EQ(observer_.num_added_tracks_, 1);
3063 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3064
3065 // Create and set the updated remote SDP.
3066 CreateAndSetRemoteOffer(kSdpStringWithStream1);
3067 EXPECT_EQ(observer_.num_added_tracks_, 2);
3068 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3069}
3070
deadbeefd1a38b52016-12-10 13:15:33 -08003071// Test that when SetConfiguration is called and the configuration is
3072// changing, the next offer causes an ICE restart.
3073TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingIceRetart) {
3074 PeerConnectionInterface::RTCConfiguration config;
3075 config.type = PeerConnectionInterface::kRelay;
3076 // Need to pass default constraints to prevent disabling of DTLS...
3077 FakeConstraints default_constraints;
3078 CreatePeerConnection(config, &default_constraints);
3079 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
3080
3081 // Do initial offer/answer so there's something to restart.
3082 CreateOfferAsLocalDescription();
3083 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
3084
3085 // Grab the ufrags.
3086 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3087
3088 // Change ICE policy, which should trigger an ICE restart on the next offer.
3089 config.type = PeerConnectionInterface::kAll;
3090 EXPECT_TRUE(pc_->SetConfiguration(config));
3091 CreateOfferAsLocalDescription();
3092
3093 // Grab the new ufrags.
3094 std::vector<std::string> subsequent_ufrags =
3095 GetUfrags(pc_->local_description());
3096
3097 // Sanity check.
3098 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3099 // Check that each ufrag is different.
3100 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3101 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3102 }
3103}
3104
3105// Test that when SetConfiguration is called and the configuration *isn't*
3106// changing, the next offer does *not* cause an ICE restart.
3107TEST_F(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRetart) {
3108 PeerConnectionInterface::RTCConfiguration config;
3109 config.type = PeerConnectionInterface::kRelay;
3110 // Need to pass default constraints to prevent disabling of DTLS...
3111 FakeConstraints default_constraints;
3112 CreatePeerConnection(config, &default_constraints);
3113 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
3114
3115 // Do initial offer/answer so there's something to restart.
3116 CreateOfferAsLocalDescription();
3117 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
3118
3119 // Grab the ufrags.
3120 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3121
3122 // Call SetConfiguration with a config identical to what the PC was
3123 // constructed with.
3124 EXPECT_TRUE(pc_->SetConfiguration(config));
3125 CreateOfferAsLocalDescription();
3126
3127 // Grab the new ufrags.
3128 std::vector<std::string> subsequent_ufrags =
3129 GetUfrags(pc_->local_description());
3130
3131 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3132}
3133
3134// Test for a weird corner case scenario:
3135// 1. Audio/video session established.
3136// 2. SetConfiguration changes ICE config; ICE restart needed.
3137// 3. ICE restart initiated by remote peer, but only for one m= section.
3138// 4. Next createOffer should initiate an ICE restart, but only for the other
3139// m= section; it would be pointless to do an ICE restart for the m= section
3140// that was already restarted.
3141TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
3142 PeerConnectionInterface::RTCConfiguration config;
3143 config.type = PeerConnectionInterface::kRelay;
3144 // Need to pass default constraints to prevent disabling of DTLS...
3145 FakeConstraints default_constraints;
3146 CreatePeerConnection(config, &default_constraints);
3147 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
3148
3149 // Do initial offer/answer so there's something to restart.
3150 CreateOfferAsLocalDescription();
3151 CreateAnswerAsRemoteDescription(kSdpStringWithStream1);
3152
3153 // Change ICE policy, which should set the "needs-ice-restart" flag.
3154 config.type = PeerConnectionInterface::kAll;
3155 EXPECT_TRUE(pc_->SetConfiguration(config));
3156
3157 // Do ICE restart for the first m= section, initiated by remote peer.
3158 webrtc::JsepSessionDescription* remote_offer =
3159 new webrtc::JsepSessionDescription(SessionDescriptionInterface::kOffer);
3160 EXPECT_TRUE(remote_offer->Initialize(kSdpStringWithStream1, nullptr));
3161 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3162 "modified";
3163 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3164 CreateAnswerAsLocalDescription();
3165
3166 // Grab the ufrags.
3167 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3168 ASSERT_EQ(2, initial_ufrags.size());
3169
3170 // Create offer and grab the new ufrags.
3171 CreateOfferAsLocalDescription();
3172 std::vector<std::string> subsequent_ufrags =
3173 GetUfrags(pc_->local_description());
3174 ASSERT_EQ(2, subsequent_ufrags.size());
3175
3176 // Ensure that only the ufrag for the second m= section changed.
3177 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3178 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3179}
3180
deadbeeffe4a8a42016-12-20 17:56:17 -08003181// Tests that the methods to return current/pending descriptions work as
3182// expected at different points in the offer/answer exchange. This test does
3183// one offer/answer exchange as the offerer, then another as the answerer.
3184TEST_F(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
3185 // This disables DTLS so we can apply an answer to ourselves.
3186 CreatePeerConnection();
3187
3188 // Create initial local offer and get SDP (which will also be used as
3189 // answer/pranswer);
3190 std::unique_ptr<SessionDescriptionInterface> offer;
3191 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3192 std::string sdp;
3193 EXPECT_TRUE(offer->ToString(&sdp));
3194
3195 // Set local offer.
3196 SessionDescriptionInterface* local_offer = offer.release();
3197 EXPECT_TRUE(DoSetLocalDescription(local_offer));
3198 EXPECT_EQ(local_offer, pc_->pending_local_description());
3199 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3200 EXPECT_EQ(nullptr, pc_->current_local_description());
3201 EXPECT_EQ(nullptr, pc_->current_remote_description());
3202
3203 // Set remote pranswer.
3204 SessionDescriptionInterface* remote_pranswer =
3205 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3206 sdp, nullptr);
3207 EXPECT_TRUE(DoSetRemoteDescription(remote_pranswer));
3208 EXPECT_EQ(local_offer, pc_->pending_local_description());
3209 EXPECT_EQ(remote_pranswer, pc_->pending_remote_description());
3210 EXPECT_EQ(nullptr, pc_->current_local_description());
3211 EXPECT_EQ(nullptr, pc_->current_remote_description());
3212
3213 // Set remote answer.
3214 SessionDescriptionInterface* remote_answer = webrtc::CreateSessionDescription(
3215 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3216 EXPECT_TRUE(DoSetRemoteDescription(remote_answer));
3217 EXPECT_EQ(nullptr, pc_->pending_local_description());
3218 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3219 EXPECT_EQ(local_offer, pc_->current_local_description());
3220 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3221
3222 // Set remote offer.
3223 SessionDescriptionInterface* remote_offer = webrtc::CreateSessionDescription(
3224 SessionDescriptionInterface::kOffer, sdp, nullptr);
3225 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
3226 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3227 EXPECT_EQ(nullptr, pc_->pending_local_description());
3228 EXPECT_EQ(local_offer, pc_->current_local_description());
3229 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3230
3231 // Set local pranswer.
3232 SessionDescriptionInterface* local_pranswer =
3233 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
3234 sdp, nullptr);
3235 EXPECT_TRUE(DoSetLocalDescription(local_pranswer));
3236 EXPECT_EQ(remote_offer, pc_->pending_remote_description());
3237 EXPECT_EQ(local_pranswer, pc_->pending_local_description());
3238 EXPECT_EQ(local_offer, pc_->current_local_description());
3239 EXPECT_EQ(remote_answer, pc_->current_remote_description());
3240
3241 // Set local answer.
3242 SessionDescriptionInterface* local_answer = webrtc::CreateSessionDescription(
3243 SessionDescriptionInterface::kAnswer, sdp, nullptr);
3244 EXPECT_TRUE(DoSetLocalDescription(local_answer));
3245 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3246 EXPECT_EQ(nullptr, pc_->pending_local_description());
3247 EXPECT_EQ(remote_offer, pc_->current_remote_description());
3248 EXPECT_EQ(local_answer, pc_->current_local_description());
3249}
3250
zhihuang77985012017-02-07 15:45:16 -08003251// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3252// after the PeerConnection is closed.
3253TEST_F(PeerConnectionInterfaceTest,
3254 StartAndStopLoggingAfterPeerConnectionClosed) {
3255 CreatePeerConnection();
3256 // The RtcEventLog will be reset when the PeerConnection is closed.
3257 pc_->Close();
3258
3259 rtc::PlatformFile file = 0;
3260 int64_t max_size_bytes = 1024;
3261 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3262 pc_->StopRtcEventLog();
3263}
3264
deadbeef30952b42017-04-21 02:41:29 -07003265// Test that generated offers/answers include "ice-option:trickle".
3266TEST_F(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
3267 CreatePeerConnection();
3268
3269 // First, create an offer with audio/video.
3270 FakeConstraints constraints;
3271 constraints.SetMandatoryReceiveAudio(true);
3272 constraints.SetMandatoryReceiveVideo(true);
3273 std::unique_ptr<SessionDescriptionInterface> offer;
3274 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3275 cricket::SessionDescription* desc = offer->description();
3276 ASSERT_EQ(2u, desc->transport_infos().size());
3277 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3278 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3279
3280 // Apply the offer as a remote description, then create an answer.
3281 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3282 std::unique_ptr<SessionDescriptionInterface> answer;
3283 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3284 desc = answer->description();
3285 ASSERT_EQ(2u, desc->transport_infos().size());
3286 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3287 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3288}
3289
deadbeef1dcb1642017-03-29 21:08:16 -07003290// Test that ICE renomination isn't offered if it's not enabled in the PC's
3291// RTCConfiguration.
3292TEST_F(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
3293 PeerConnectionInterface::RTCConfiguration config;
3294 config.enable_ice_renomination = false;
3295 CreatePeerConnection(config, nullptr);
3296 AddVoiceStream("foo");
3297
3298 std::unique_ptr<SessionDescriptionInterface> offer;
3299 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3300 cricket::SessionDescription* desc = offer->description();
3301 EXPECT_EQ(1u, desc->transport_infos().size());
3302 EXPECT_FALSE(
3303 desc->transport_infos()[0].description.GetIceParameters().renomination);
3304}
3305
3306// Test that the ICE renomination option is present in generated offers/answers
3307// if it's enabled in the PC's RTCConfiguration.
3308TEST_F(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
3309 PeerConnectionInterface::RTCConfiguration config;
3310 config.enable_ice_renomination = true;
3311 CreatePeerConnection(config, nullptr);
3312 AddVoiceStream("foo");
3313
3314 std::unique_ptr<SessionDescriptionInterface> offer;
3315 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3316 cricket::SessionDescription* desc = offer->description();
3317 EXPECT_EQ(1u, desc->transport_infos().size());
3318 EXPECT_TRUE(
3319 desc->transport_infos()[0].description.GetIceParameters().renomination);
3320
3321 // Set the offer as a remote description, then create an answer and ensure it
3322 // has the renomination flag too.
3323 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3324 std::unique_ptr<SessionDescriptionInterface> answer;
3325 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3326 desc = answer->description();
3327 EXPECT_EQ(1u, desc->transport_infos().size());
3328 EXPECT_TRUE(
3329 desc->transport_infos()[0].description.GetIceParameters().renomination);
3330}
3331
3332// Test that if CreateOffer is called with the deprecated "offer to receive
3333// audio/video" constraints, they're processed and result in an offer with
3334// audio/video sections just as if RTCOfferAnswerOptions had been used.
3335TEST_F(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
3336 CreatePeerConnection();
3337
3338 FakeConstraints constraints;
3339 constraints.SetMandatoryReceiveAudio(true);
3340 constraints.SetMandatoryReceiveVideo(true);
3341 std::unique_ptr<SessionDescriptionInterface> offer;
3342 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3343
3344 cricket::SessionDescription* desc = offer->description();
3345 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3346 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3347 ASSERT_NE(nullptr, audio);
3348 ASSERT_NE(nullptr, video);
3349 EXPECT_FALSE(audio->rejected);
3350 EXPECT_FALSE(video->rejected);
3351}
3352
3353// Test that if CreateAnswer is called with the deprecated "offer to receive
3354// audio/video" constraints, they're processed and can be used to reject an
3355// offered m= section just as can be done with RTCOfferAnswerOptions;
3356TEST_F(PeerConnectionInterfaceTest, CreateAnswerWithOfferToReceiveConstraints) {
3357 CreatePeerConnection();
3358
3359 // First, create an offer with audio/video and apply it as a remote
3360 // description.
3361 FakeConstraints constraints;
3362 constraints.SetMandatoryReceiveAudio(true);
3363 constraints.SetMandatoryReceiveVideo(true);
3364 std::unique_ptr<SessionDescriptionInterface> offer;
3365 ASSERT_TRUE(DoCreateOffer(&offer, &constraints));
3366 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3367
3368 // Now create answer that rejects audio/video.
3369 constraints.SetMandatoryReceiveAudio(false);
3370 constraints.SetMandatoryReceiveVideo(false);
3371 std::unique_ptr<SessionDescriptionInterface> answer;
3372 ASSERT_TRUE(DoCreateAnswer(&answer, &constraints));
3373
3374 cricket::SessionDescription* desc = answer->description();
3375 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3376 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3377 ASSERT_NE(nullptr, audio);
3378 ASSERT_NE(nullptr, video);
3379 EXPECT_TRUE(audio->rejected);
3380 EXPECT_TRUE(video->rejected);
3381}
3382
3383#ifdef HAVE_SCTP
3384#define MAYBE_DataChannelOnlyOfferWithMaxBundlePolicy \
3385 DataChannelOnlyOfferWithMaxBundlePolicy
3386#else
3387#define MAYBE_DataChannelOnlyOfferWithMaxBundlePolicy \
3388 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy
3389#endif
3390
3391// Test that negotiation can succeed with a data channel only, and with the max
3392// bundle policy. Previously there was a bug that prevented this.
3393TEST_F(PeerConnectionInterfaceTest,
3394 MAYBE_DataChannelOnlyOfferWithMaxBundlePolicy) {
3395 PeerConnectionInterface::RTCConfiguration config;
3396 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3397 CreatePeerConnection(config, nullptr);
3398
3399 // First, create an offer with only a data channel and apply it as a remote
3400 // description.
3401 pc_->CreateDataChannel("test", nullptr);
3402 std::unique_ptr<SessionDescriptionInterface> offer;
3403 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3404 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
3405
3406 // Create and set answer as well.
3407 std::unique_ptr<SessionDescriptionInterface> answer;
3408 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3409 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
3410}
3411
zstein4b979802017-06-02 14:37:37 -07003412TEST_F(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
3413 CreatePeerConnection();
3414 PeerConnectionInterface::BitrateParameters bitrate;
3415 bitrate.current_bitrate_bps = rtc::Optional<int>(100000);
3416 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3417}
3418
3419TEST_F(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
3420 CreatePeerConnection();
3421 PeerConnectionInterface::BitrateParameters bitrate;
3422 bitrate.min_bitrate_bps = rtc::Optional<int>(-1);
3423 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3424}
3425
3426TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
3427 CreatePeerConnection();
3428 PeerConnectionInterface::BitrateParameters bitrate;
3429 bitrate.min_bitrate_bps = rtc::Optional<int>(5);
3430 bitrate.current_bitrate_bps = rtc::Optional<int>(3);
3431 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3432}
3433
3434TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
3435 CreatePeerConnection();
3436 PeerConnectionInterface::BitrateParameters bitrate;
3437 bitrate.current_bitrate_bps = rtc::Optional<int>(-1);
3438 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3439}
3440
3441TEST_F(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
3442 CreatePeerConnection();
3443 PeerConnectionInterface::BitrateParameters bitrate;
3444 bitrate.current_bitrate_bps = rtc::Optional<int>(10);
3445 bitrate.max_bitrate_bps = rtc::Optional<int>(8);
3446 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3447}
3448
3449TEST_F(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
3450 CreatePeerConnection();
3451 PeerConnectionInterface::BitrateParameters bitrate;
3452 bitrate.min_bitrate_bps = rtc::Optional<int>(10);
3453 bitrate.max_bitrate_bps = rtc::Optional<int>(8);
3454 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3455}
3456
3457TEST_F(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
3458 CreatePeerConnection();
3459 PeerConnectionInterface::BitrateParameters bitrate;
3460 bitrate.max_bitrate_bps = rtc::Optional<int>(-1);
3461 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3462}
3463
Steve Anton038834f2017-07-14 15:59:59 -07003464// ice_regather_interval_range requires WebRTC to be configured for continual
3465// gathering already.
3466TEST_F(PeerConnectionInterfaceTest,
3467 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3468 PeerConnectionInterface::RTCConfiguration config;
3469 config.ice_regather_interval_range.emplace(1000, 2000);
3470 config.continual_gathering_policy =
3471 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3472 CreatePeerConnectionExpectFail(config);
3473}
3474
3475// Ensures that there is no error when ice_regather_interval_range is set with
3476// continual gathering enabled.
3477TEST_F(PeerConnectionInterfaceTest,
3478 SetIceRegatherIntervalRangeWithContinualGathering) {
3479 PeerConnectionInterface::RTCConfiguration config;
3480 config.ice_regather_interval_range.emplace(1000, 2000);
3481 config.continual_gathering_policy =
3482 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
3483 CreatePeerConnection(config, nullptr);
3484}
3485
zstein4b979802017-06-02 14:37:37 -07003486// The current bitrate from Call's BitrateConfigMask is currently clamped by
3487// Call's BitrateConfig, which comes from the SDP or a default value. This test
3488// checks that a call to SetBitrate with a current bitrate that will be clamped
3489// succeeds.
3490TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
3491 CreatePeerConnection();
3492 PeerConnectionInterface::BitrateParameters bitrate;
3493 bitrate.current_bitrate_bps = rtc::Optional<int>(1);
3494 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3495}
3496
nisse51542be2016-02-12 02:27:06 -08003497class PeerConnectionMediaConfigTest : public testing::Test {
3498 protected:
3499 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003500 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003501 pcf_->Initialize();
3502 }
nisseeaabdf62017-05-05 02:23:02 -07003503 const cricket::MediaConfig TestCreatePeerConnection(
nisse51542be2016-02-12 02:27:06 -08003504 const PeerConnectionInterface::RTCConfiguration& config,
3505 const MediaConstraintsInterface *constraints) {
nisse51542be2016-02-12 02:27:06 -08003506
zhihuang9763d562016-08-05 11:14:50 -07003507 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
3508 config, constraints, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003509 EXPECT_TRUE(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003510 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003511 }
3512
zhihuang9763d562016-08-05 11:14:50 -07003513 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003514 MockPeerConnectionObserver observer_;
3515};
3516
3517// This test verifies the default behaviour with no constraints and a
3518// default RTCConfiguration.
3519TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3520 PeerConnectionInterface::RTCConfiguration config;
3521 FakeConstraints constraints;
3522
3523 const cricket::MediaConfig& media_config =
3524 TestCreatePeerConnection(config, &constraints);
3525
3526 EXPECT_FALSE(media_config.enable_dscp);
nisse0db023a2016-03-01 04:29:59 -08003527 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection);
3528 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing);
3529 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003530}
3531
3532// This test verifies the DSCP constraint is recognized and passed to
nisse528b7932017-05-08 03:21:43 -07003533// the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003534TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
3535 PeerConnectionInterface::RTCConfiguration config;
3536 FakeConstraints constraints;
3537
3538 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
3539 const cricket::MediaConfig& media_config =
3540 TestCreatePeerConnection(config, &constraints);
3541
3542 EXPECT_TRUE(media_config.enable_dscp);
3543}
3544
3545// This test verifies the cpu overuse detection constraint is
nisse528b7932017-05-08 03:21:43 -07003546// recognized and passed to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003547TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
3548 PeerConnectionInterface::RTCConfiguration config;
3549 FakeConstraints constraints;
3550
3551 constraints.AddOptional(
3552 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
3553 const cricket::MediaConfig media_config =
3554 TestCreatePeerConnection(config, &constraints);
3555
nisse0db023a2016-03-01 04:29:59 -08003556 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection);
nisse51542be2016-02-12 02:27:06 -08003557}
3558
3559// This test verifies that the disable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003560// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003561TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3562 PeerConnectionInterface::RTCConfiguration config;
3563 FakeConstraints constraints;
3564
Niels Möller71bdda02016-03-31 12:59:59 +02003565 config.set_prerenderer_smoothing(false);
nisse51542be2016-02-12 02:27:06 -08003566 const cricket::MediaConfig& media_config =
3567 TestCreatePeerConnection(config, &constraints);
3568
nisse0db023a2016-03-01 04:29:59 -08003569 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing);
3570}
3571
3572// This test verifies the suspend below min bitrate constraint is
nisse528b7932017-05-08 03:21:43 -07003573// recognized and passed to the PeerConnection.
nisse0db023a2016-03-01 04:29:59 -08003574TEST_F(PeerConnectionMediaConfigTest,
3575 TestSuspendBelowMinBitrateConstraintTrue) {
3576 PeerConnectionInterface::RTCConfiguration config;
3577 FakeConstraints constraints;
3578
3579 constraints.AddOptional(
3580 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3581 true);
3582 const cricket::MediaConfig media_config =
3583 TestCreatePeerConnection(config, &constraints);
3584
3585 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
nisse51542be2016-02-12 02:27:06 -08003586}
3587
deadbeefab9b2d12015-10-14 11:33:11 -07003588// The following tests verify that session options are created correctly.
deadbeefc80741f2015-10-22 13:14:45 -07003589// TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
3590// "verify options are converted correctly", should be "pass options into
3591// CreateOffer and verify the correct offer is produced."
deadbeefab9b2d12015-10-14 11:33:11 -07003592
3593TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
3594 RTCOfferAnswerOptions rtc_options;
3595 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3596
3597 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003598 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003599
3600 rtc_options.offer_to_receive_audio =
3601 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003602 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003603}
3604
3605TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
3606 RTCOfferAnswerOptions rtc_options;
3607 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3608
3609 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003610 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003611
3612 rtc_options.offer_to_receive_video =
3613 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
htaaac2dea2016-03-10 13:35:55 -08003614 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003615}
3616
3617// Test that a MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003618// OfferToReceiveAudio and OfferToReceiveVideo options are set.
deadbeefab9b2d12015-10-14 11:33:11 -07003619TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
3620 RTCOfferAnswerOptions rtc_options;
3621 rtc_options.offer_to_receive_audio = 1;
3622 rtc_options.offer_to_receive_video = 1;
3623
3624 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003625 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003626 EXPECT_TRUE(options.has_audio());
3627 EXPECT_TRUE(options.has_video());
3628 EXPECT_TRUE(options.bundle_enabled);
3629}
3630
3631// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003632// OfferToReceiveAudio is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003633TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
3634 RTCOfferAnswerOptions rtc_options;
3635 rtc_options.offer_to_receive_audio = 1;
3636
3637 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003638 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003639 EXPECT_TRUE(options.has_audio());
3640 EXPECT_FALSE(options.has_video());
3641 EXPECT_TRUE(options.bundle_enabled);
3642}
3643
3644// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003645// the default OfferOptions are used.
deadbeefab9b2d12015-10-14 11:33:11 -07003646TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
3647 RTCOfferAnswerOptions rtc_options;
3648
3649 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003650 options.transport_options["audio"] = cricket::TransportOptions();
3651 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003652 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefc80741f2015-10-22 13:14:45 -07003653 EXPECT_TRUE(options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07003654 EXPECT_FALSE(options.has_video());
deadbeefc80741f2015-10-22 13:14:45 -07003655 EXPECT_TRUE(options.bundle_enabled);
deadbeefab9b2d12015-10-14 11:33:11 -07003656 EXPECT_TRUE(options.vad_enabled);
deadbeef0ed85b22016-02-23 17:24:52 -08003657 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3658 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003659}
3660
3661// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07003662// OfferToReceiveVideo is set.
deadbeefab9b2d12015-10-14 11:33:11 -07003663TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
3664 RTCOfferAnswerOptions rtc_options;
3665 rtc_options.offer_to_receive_audio = 0;
3666 rtc_options.offer_to_receive_video = 1;
3667
3668 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003669 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003670 EXPECT_FALSE(options.has_audio());
3671 EXPECT_TRUE(options.has_video());
3672 EXPECT_TRUE(options.bundle_enabled);
3673}
3674
3675// Test that a correct MediaSessionOptions is created for an offer if
3676// UseRtpMux is set to false.
3677TEST(CreateSessionOptionsTest,
3678 GetMediaSessionOptionsForOfferWithBundleDisabled) {
3679 RTCOfferAnswerOptions rtc_options;
3680 rtc_options.offer_to_receive_audio = 1;
3681 rtc_options.offer_to_receive_video = 1;
3682 rtc_options.use_rtp_mux = false;
3683
3684 cricket::MediaSessionOptions options;
htaaac2dea2016-03-10 13:35:55 -08003685 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeefab9b2d12015-10-14 11:33:11 -07003686 EXPECT_TRUE(options.has_audio());
3687 EXPECT_TRUE(options.has_video());
3688 EXPECT_FALSE(options.bundle_enabled);
3689}
3690
3691// Test that a correct MediaSessionOptions is created to restart ice if
3692// IceRestart is set. It also tests that subsequent MediaSessionOptions don't
Taylor Brandstetterf475d362016-01-08 15:35:57 -08003693// have |audio_transport_options.ice_restart| etc. set.
deadbeefab9b2d12015-10-14 11:33:11 -07003694TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
3695 RTCOfferAnswerOptions rtc_options;
3696 rtc_options.ice_restart = true;
3697
3698 cricket::MediaSessionOptions options;
deadbeef0ed85b22016-02-23 17:24:52 -08003699 options.transport_options["audio"] = cricket::TransportOptions();
3700 options.transport_options["video"] = cricket::TransportOptions();
htaaac2dea2016-03-10 13:35:55 -08003701 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003702 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
3703 EXPECT_TRUE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003704
3705 rtc_options = RTCOfferAnswerOptions();
htaaac2dea2016-03-10 13:35:55 -08003706 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
deadbeef0ed85b22016-02-23 17:24:52 -08003707 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
3708 EXPECT_FALSE(options.transport_options["video"].ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07003709}
3710
3711// Test that the MediaConstraints in an answer don't affect if audio and video
3712// is offered in an offer but that if kOfferToReceiveAudio or
3713// kOfferToReceiveVideo constraints are true in an offer, the media type will be
3714// included in subsequent answers.
3715TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
3716 FakeConstraints answer_c;
3717 answer_c.SetMandatoryReceiveAudio(true);
3718 answer_c.SetMandatoryReceiveVideo(true);
3719
3720 cricket::MediaSessionOptions answer_options;
3721 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
3722 EXPECT_TRUE(answer_options.has_audio());
3723 EXPECT_TRUE(answer_options.has_video());
3724
deadbeefc80741f2015-10-22 13:14:45 -07003725 RTCOfferAnswerOptions rtc_offer_options;
deadbeefab9b2d12015-10-14 11:33:11 -07003726
3727 cricket::MediaSessionOptions offer_options;
htaaac2dea2016-03-10 13:35:55 -08003728 EXPECT_TRUE(
3729 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
deadbeefc80741f2015-10-22 13:14:45 -07003730 EXPECT_TRUE(offer_options.has_audio());
htaaac2dea2016-03-10 13:35:55 -08003731 EXPECT_TRUE(offer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003732
deadbeefc80741f2015-10-22 13:14:45 -07003733 RTCOfferAnswerOptions updated_rtc_offer_options;
3734 updated_rtc_offer_options.offer_to_receive_audio = 1;
3735 updated_rtc_offer_options.offer_to_receive_video = 1;
deadbeefab9b2d12015-10-14 11:33:11 -07003736
3737 cricket::MediaSessionOptions updated_offer_options;
htaaac2dea2016-03-10 13:35:55 -08003738 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
htaa2a49d92016-03-04 02:51:39 -08003739 &updated_offer_options));
deadbeefab9b2d12015-10-14 11:33:11 -07003740 EXPECT_TRUE(updated_offer_options.has_audio());
3741 EXPECT_TRUE(updated_offer_options.has_video());
3742
3743 // Since an offer has been created with both audio and video, subsequent
3744 // offers and answers should contain both audio and video.
3745 // Answers will only contain the media types that exist in the offer
3746 // regardless of the value of |updated_answer_options.has_audio| and
3747 // |updated_answer_options.has_video|.
3748 FakeConstraints updated_answer_c;
3749 answer_c.SetMandatoryReceiveAudio(false);
3750 answer_c.SetMandatoryReceiveVideo(false);
3751
3752 cricket::MediaSessionOptions updated_answer_options;
3753 EXPECT_TRUE(
3754 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
3755 EXPECT_TRUE(updated_answer_options.has_audio());
3756 EXPECT_TRUE(updated_answer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07003757}
deadbeef3edec7c2016-12-10 11:44:26 -08003758
deadbeef293e9262017-01-11 12:28:30 -08003759// Tests a few random fields being different.
3760TEST(RTCConfigurationTest, ComparisonOperators) {
3761 PeerConnectionInterface::RTCConfiguration a;
3762 PeerConnectionInterface::RTCConfiguration b;
3763 EXPECT_EQ(a, b);
3764
3765 PeerConnectionInterface::RTCConfiguration c;
3766 c.servers.push_back(PeerConnectionInterface::IceServer());
3767 EXPECT_NE(a, c);
3768
3769 PeerConnectionInterface::RTCConfiguration d;
3770 d.type = PeerConnectionInterface::kRelay;
3771 EXPECT_NE(a, d);
3772
3773 PeerConnectionInterface::RTCConfiguration e;
3774 e.audio_jitter_buffer_max_packets = 5;
3775 EXPECT_NE(a, e);
3776
3777 PeerConnectionInterface::RTCConfiguration f;
3778 f.ice_connection_receiving_timeout = 1337;
3779 EXPECT_NE(a, f);
3780
3781 PeerConnectionInterface::RTCConfiguration g;
3782 g.disable_ipv6 = true;
3783 EXPECT_NE(a, g);
3784
3785 PeerConnectionInterface::RTCConfiguration h(
3786 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3787 EXPECT_NE(a, h);
3788}
korniltsev.anatolyec390b52017-07-24 17:00:25 -07003789
3790// This test ensures OnRenegotiationNeeded is called when we add track with
3791// MediaStream -> AddTrack in the same way it is called when we add track with
3792// PeerConnection -> AddTrack.
3793// The test can be removed once addStream is rewritten in terms of addTrack
3794// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
3795TEST_F(PeerConnectionInterfaceTest, MediaStreamAddTrackRemoveTrackRenegotiate) {
3796 CreatePeerConnectionWithoutDtls();
3797 rtc::scoped_refptr<MediaStreamInterface> stream(
3798 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
3799 pc_->AddStream(stream);
3800 rtc::scoped_refptr<AudioTrackInterface> audio_track(
3801 pc_factory_->CreateAudioTrack("audio_track", nullptr));
3802 rtc::scoped_refptr<VideoTrackInterface> video_track(
3803 pc_factory_->CreateVideoTrack(
3804 "video_track", pc_factory_->CreateVideoSource(
3805 std::unique_ptr<cricket::VideoCapturer>(
3806 new cricket::FakeVideoCapturer()))));
3807 stream->AddTrack(audio_track);
3808 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3809 observer_.renegotiation_needed_ = false;
3810
3811 stream->AddTrack(video_track);
3812 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3813 observer_.renegotiation_needed_ = false;
3814
3815 stream->RemoveTrack(audio_track);
3816 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3817 observer_.renegotiation_needed_ = false;
3818
3819 stream->RemoveTrack(video_track);
3820 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3821 observer_.renegotiation_needed_ = false;
3822}