blob: b1f718b460c7618248c17dc5008bcc7d4facbbb6 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080029#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
deadbeefab9b2d12015-10-14 11:33:11 -070031#include "talk/app/webrtc/audiotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032#include "talk/app/webrtc/jsepsessiondescription.h"
deadbeefab9b2d12015-10-14 11:33:11 -070033#include "talk/app/webrtc/mediastream.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/mediastreaminterface.h"
deadbeefab9b2d12015-10-14 11:33:11 -070035#include "talk/app/webrtc/peerconnection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/app/webrtc/peerconnectioninterface.h"
deadbeefab9b2d12015-10-14 11:33:11 -070037#include "talk/app/webrtc/rtpreceiverinterface.h"
38#include "talk/app/webrtc/rtpsenderinterface.h"
39#include "talk/app/webrtc/streamcollection.h"
phoglund37ebcf02016-01-08 05:04:57 -080040#ifdef WEBRTC_ANDROID
41#include "talk/app/webrtc/test/androidtestinitializer.h"
42#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020044#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045#include "talk/app/webrtc/test/mockpeerconnectionobservers.h"
46#include "talk/app/webrtc/test/testsdpstrings.h"
wu@webrtc.org967bfff2013-09-19 05:49:50 +000047#include "talk/app/webrtc/videosource.h"
deadbeefab9b2d12015-10-14 11:33:11 -070048#include "talk/app/webrtc/videotrack.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/media/base/fakevideocapturer.h"
50#include "talk/media/sctp/sctpdataengine.h"
51#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052#include "webrtc/base/gunit.h"
53#include "webrtc/base/scoped_ptr.h"
54#include "webrtc/base/ssladapter.h"
55#include "webrtc/base/sslstreamadapter.h"
56#include "webrtc/base/stringutils.h"
57#include "webrtc/base/thread.h"
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080058#include "webrtc/p2p/client/fakeportallocator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
60static const char kStreamLabel1[] = "local_stream_1";
61static const char kStreamLabel2[] = "local_stream_2";
62static const char kStreamLabel3[] = "local_stream_3";
63static const int kDefaultStunPort = 3478;
64static const char kStunAddressOnly[] = "stun:address";
65static const char kStunInvalidPort[] = "stun:address:-1";
66static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
67static const char kStunAddressPortAndMore2[] = "stun:address:port more";
68static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
69static const char kTurnUsername[] = "user";
70static const char kTurnPassword[] = "password";
71static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +020072static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
deadbeefab9b2d12015-10-14 11:33:11 -070074static const char kStreams[][8] = {"stream1", "stream2"};
75static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
76static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
77
deadbeef5e97fb52015-10-15 12:49:08 -070078static const char kRecvonly[] = "recvonly";
79static const char kSendrecv[] = "sendrecv";
80
deadbeefab9b2d12015-10-14 11:33:11 -070081// Reference SDP with a MediaStream with label "stream1" and audio track with
82// id "audio_1" and a video track with id "video_1;
83static const char kSdpStringWithStream1[] =
84 "v=0\r\n"
85 "o=- 0 0 IN IP4 127.0.0.1\r\n"
86 "s=-\r\n"
87 "t=0 0\r\n"
88 "a=ice-ufrag:e5785931\r\n"
89 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
90 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
91 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
92 "m=audio 1 RTP/AVPF 103\r\n"
93 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -070094 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -070095 "a=rtpmap:103 ISAC/16000\r\n"
96 "a=ssrc:1 cname:stream1\r\n"
97 "a=ssrc:1 mslabel:stream1\r\n"
98 "a=ssrc:1 label:audiotrack0\r\n"
99 "m=video 1 RTP/AVPF 120\r\n"
100 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700101 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700102 "a=rtpmap:120 VP8/90000\r\n"
103 "a=ssrc:2 cname:stream1\r\n"
104 "a=ssrc:2 mslabel:stream1\r\n"
105 "a=ssrc:2 label:videotrack0\r\n";
106
107// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
108// MediaStreams have one audio track and one video track.
109// This uses MSID.
110static const char kSdpStringWithStream1And2[] =
111 "v=0\r\n"
112 "o=- 0 0 IN IP4 127.0.0.1\r\n"
113 "s=-\r\n"
114 "t=0 0\r\n"
115 "a=ice-ufrag:e5785931\r\n"
116 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
117 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
118 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
119 "a=msid-semantic: WMS stream1 stream2\r\n"
120 "m=audio 1 RTP/AVPF 103\r\n"
121 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700122 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700123 "a=rtpmap:103 ISAC/16000\r\n"
124 "a=ssrc:1 cname:stream1\r\n"
125 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
126 "a=ssrc:3 cname:stream2\r\n"
127 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
128 "m=video 1 RTP/AVPF 120\r\n"
129 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700130 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700131 "a=rtpmap:120 VP8/0\r\n"
132 "a=ssrc:2 cname:stream1\r\n"
133 "a=ssrc:2 msid:stream1 videotrack0\r\n"
134 "a=ssrc:4 cname:stream2\r\n"
135 "a=ssrc:4 msid:stream2 videotrack1\r\n";
136
137// Reference SDP without MediaStreams. Msid is not supported.
138static const char kSdpStringWithoutStreams[] =
139 "v=0\r\n"
140 "o=- 0 0 IN IP4 127.0.0.1\r\n"
141 "s=-\r\n"
142 "t=0 0\r\n"
143 "a=ice-ufrag:e5785931\r\n"
144 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
145 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
146 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
147 "m=audio 1 RTP/AVPF 103\r\n"
148 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700149 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700150 "a=rtpmap:103 ISAC/16000\r\n"
151 "m=video 1 RTP/AVPF 120\r\n"
152 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700153 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700154 "a=rtpmap:120 VP8/90000\r\n";
155
156// Reference SDP without MediaStreams. Msid is supported.
157static const char kSdpStringWithMsidWithoutStreams[] =
158 "v=0\r\n"
159 "o=- 0 0 IN IP4 127.0.0.1\r\n"
160 "s=-\r\n"
161 "t=0 0\r\n"
162 "a=ice-ufrag:e5785931\r\n"
163 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
164 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
165 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
166 "a=msid-semantic: WMS\r\n"
167 "m=audio 1 RTP/AVPF 103\r\n"
168 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700169 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700170 "a=rtpmap:103 ISAC/16000\r\n"
171 "m=video 1 RTP/AVPF 120\r\n"
172 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700173 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700174 "a=rtpmap:120 VP8/90000\r\n";
175
176// Reference SDP without MediaStreams and audio only.
177static const char kSdpStringWithoutStreamsAudioOnly[] =
178 "v=0\r\n"
179 "o=- 0 0 IN IP4 127.0.0.1\r\n"
180 "s=-\r\n"
181 "t=0 0\r\n"
182 "a=ice-ufrag:e5785931\r\n"
183 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
184 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
185 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
186 "m=audio 1 RTP/AVPF 103\r\n"
187 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700188 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700189 "a=rtpmap:103 ISAC/16000\r\n";
190
191// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
192static const char kSdpStringSendOnlyWithoutStreams[] =
193 "v=0\r\n"
194 "o=- 0 0 IN IP4 127.0.0.1\r\n"
195 "s=-\r\n"
196 "t=0 0\r\n"
197 "a=ice-ufrag:e5785931\r\n"
198 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
199 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
200 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
201 "m=audio 1 RTP/AVPF 103\r\n"
202 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700203 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700204 "a=sendonly\r\n"
205 "a=rtpmap:103 ISAC/16000\r\n"
206 "m=video 1 RTP/AVPF 120\r\n"
207 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700208 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700209 "a=sendonly\r\n"
210 "a=rtpmap:120 VP8/90000\r\n";
211
212static const char kSdpStringInit[] =
213 "v=0\r\n"
214 "o=- 0 0 IN IP4 127.0.0.1\r\n"
215 "s=-\r\n"
216 "t=0 0\r\n"
217 "a=ice-ufrag:e5785931\r\n"
218 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
219 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
220 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
221 "a=msid-semantic: WMS\r\n";
222
223static const char kSdpStringAudio[] =
224 "m=audio 1 RTP/AVPF 103\r\n"
225 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700226 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700227 "a=rtpmap:103 ISAC/16000\r\n";
228
229static const char kSdpStringVideo[] =
230 "m=video 1 RTP/AVPF 120\r\n"
231 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700232 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700233 "a=rtpmap:120 VP8/90000\r\n";
234
235static const char kSdpStringMs1Audio0[] =
236 "a=ssrc:1 cname:stream1\r\n"
237 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
238
239static const char kSdpStringMs1Video0[] =
240 "a=ssrc:2 cname:stream1\r\n"
241 "a=ssrc:2 msid:stream1 videotrack0\r\n";
242
243static const char kSdpStringMs1Audio1[] =
244 "a=ssrc:3 cname:stream1\r\n"
245 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
246
247static const char kSdpStringMs1Video1[] =
248 "a=ssrc:4 cname:stream1\r\n"
249 "a=ssrc:4 msid:stream1 videotrack1\r\n";
250
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251#define MAYBE_SKIP_TEST(feature) \
252 if (!(feature())) { \
253 LOG(LS_INFO) << "Feature disabled... skipping"; \
254 return; \
255 }
256
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000257using rtc::scoped_ptr;
258using rtc::scoped_refptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259using webrtc::AudioSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700260using webrtc::AudioTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261using webrtc::AudioTrackInterface;
262using webrtc::DataBuffer;
263using webrtc::DataChannelInterface;
264using webrtc::FakeConstraints;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265using webrtc::IceCandidateInterface;
deadbeefc80741f2015-10-22 13:14:45 -0700266using webrtc::MediaConstraintsInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700267using webrtc::MediaStream;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268using webrtc::MediaStreamInterface;
269using webrtc::MediaStreamTrackInterface;
270using webrtc::MockCreateSessionDescriptionObserver;
271using webrtc::MockDataChannelObserver;
272using webrtc::MockSetSessionDescriptionObserver;
273using webrtc::MockStatsObserver;
274using webrtc::PeerConnectionInterface;
275using webrtc::PeerConnectionObserver;
deadbeefab9b2d12015-10-14 11:33:11 -0700276using webrtc::RtpReceiverInterface;
277using webrtc::RtpSenderInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278using webrtc::SdpParseError;
279using webrtc::SessionDescriptionInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700280using webrtc::StreamCollection;
281using webrtc::StreamCollectionInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282using webrtc::VideoSourceInterface;
deadbeefab9b2d12015-10-14 11:33:11 -0700283using webrtc::VideoTrack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284using webrtc::VideoTrackInterface;
285
deadbeefab9b2d12015-10-14 11:33:11 -0700286typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
287
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288namespace {
289
290// Gets the first ssrc of given content type from the ContentInfo.
291bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
292 if (!content_info || !ssrc) {
293 return false;
294 }
295 const cricket::MediaContentDescription* media_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000296 static_cast<const cricket::MediaContentDescription*>(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 content_info->description);
298 if (!media_desc || media_desc->streams().empty()) {
299 return false;
300 }
301 *ssrc = media_desc->streams().begin()->first_ssrc();
302 return true;
303}
304
305void SetSsrcToZero(std::string* sdp) {
306 const char kSdpSsrcAtribute[] = "a=ssrc:";
307 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
308 size_t ssrc_pos = 0;
309 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
310 std::string::npos) {
311 size_t end_ssrc = sdp->find(" ", ssrc_pos);
312 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
313 ssrc_pos = end_ssrc;
314 }
315}
316
deadbeefab9b2d12015-10-14 11:33:11 -0700317// Check if |streams| contains the specified track.
318bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
319 const std::string& stream_label,
320 const std::string& track_id) {
321 for (const cricket::StreamParams& params : streams) {
322 if (params.sync_label == stream_label && params.id == track_id) {
323 return true;
324 }
325 }
326 return false;
327}
328
329// Check if |senders| contains the specified sender, by id.
330bool ContainsSender(
331 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
332 const std::string& id) {
333 for (const auto& sender : senders) {
334 if (sender->id() == id) {
335 return true;
336 }
337 }
338 return false;
339}
340
341// Create a collection of streams.
342// CreateStreamCollection(1) creates a collection that
343// correspond to kSdpStringWithStream1.
344// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
345rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
346 int number_of_streams) {
347 rtc::scoped_refptr<StreamCollection> local_collection(
348 StreamCollection::Create());
349
350 for (int i = 0; i < number_of_streams; ++i) {
351 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
352 webrtc::MediaStream::Create(kStreams[i]));
353
354 // Add a local audio track.
355 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
356 webrtc::AudioTrack::Create(kAudioTracks[i], nullptr));
357 stream->AddTrack(audio_track);
358
359 // Add a local video track.
360 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
361 webrtc::VideoTrack::Create(kVideoTracks[i], nullptr));
362 stream->AddTrack(video_track);
363
364 local_collection->AddStream(stream);
365 }
366 return local_collection;
367}
368
369// Check equality of StreamCollections.
370bool CompareStreamCollections(StreamCollectionInterface* s1,
371 StreamCollectionInterface* s2) {
372 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
373 return false;
374 }
375
376 for (size_t i = 0; i != s1->count(); ++i) {
377 if (s1->at(i)->label() != s2->at(i)->label()) {
378 return false;
379 }
380 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
381 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
382 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
383 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
384
385 if (audio_tracks1.size() != audio_tracks2.size()) {
386 return false;
387 }
388 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
389 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
390 return false;
391 }
392 }
393 if (video_tracks1.size() != video_tracks2.size()) {
394 return false;
395 }
396 for (size_t j = 0; j != video_tracks1.size(); ++j) {
397 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
398 return false;
399 }
400 }
401 }
402 return true;
403}
404
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405class MockPeerConnectionObserver : public PeerConnectionObserver {
406 public:
deadbeefab9b2d12015-10-14 11:33:11 -0700407 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 ~MockPeerConnectionObserver() {
409 }
410 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
411 pc_ = pc;
412 if (pc) {
413 state_ = pc_->signaling_state();
414 }
415 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 virtual void OnSignalingChange(
417 PeerConnectionInterface::SignalingState new_state) {
418 EXPECT_EQ(pc_->signaling_state(), new_state);
419 state_ = new_state;
420 }
421 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
422 virtual void OnStateChange(StateType state_changed) {
423 if (pc_.get() == NULL)
424 return;
425 switch (state_changed) {
426 case kSignalingState:
427 // OnSignalingChange and OnStateChange(kSignalingState) should always
428 // be called approximately simultaneously. To ease testing, we require
429 // that they always be called in that order. This check verifies
430 // that OnSignalingChange has just been called.
431 EXPECT_EQ(pc_->signaling_state(), state_);
432 break;
433 case kIceState:
434 ADD_FAILURE();
435 break;
436 default:
437 ADD_FAILURE();
438 break;
439 }
440 }
deadbeefab9b2d12015-10-14 11:33:11 -0700441
442 MediaStreamInterface* RemoteStream(const std::string& label) {
443 return remote_streams_->find(label);
444 }
445 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 virtual void OnAddStream(MediaStreamInterface* stream) {
447 last_added_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700448 remote_streams_->AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 }
450 virtual void OnRemoveStream(MediaStreamInterface* stream) {
451 last_removed_stream_ = stream;
deadbeefab9b2d12015-10-14 11:33:11 -0700452 remote_streams_->RemoveStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 }
454 virtual void OnRenegotiationNeeded() {
455 renegotiation_needed_ = true;
456 }
457 virtual void OnDataChannel(DataChannelInterface* data_channel) {
458 last_datachannel_ = data_channel;
459 }
460
461 virtual void OnIceConnectionChange(
462 PeerConnectionInterface::IceConnectionState new_state) {
463 EXPECT_EQ(pc_->ice_connection_state(), new_state);
464 }
465 virtual void OnIceGatheringChange(
466 PeerConnectionInterface::IceGatheringState new_state) {
467 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
468 }
469 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
470 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
471 pc_->ice_gathering_state());
472
473 std::string sdp;
474 EXPECT_TRUE(candidate->ToString(&sdp));
475 EXPECT_LT(0u, sdp.size());
476 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
477 candidate->sdp_mline_index(), sdp, NULL));
478 EXPECT_TRUE(last_candidate_.get() != NULL);
479 }
480 // TODO(bemasc): Remove this once callers transition to OnSignalingChange.
481 virtual void OnIceComplete() {
482 ice_complete_ = true;
483 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
484 // be called approximately simultaneously. For ease of testing, this
485 // check additionally requires that they be called in the above order.
486 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
487 pc_->ice_gathering_state());
488 }
489
490 // Returns the label of the last added stream.
491 // Empty string if no stream have been added.
492 std::string GetLastAddedStreamLabel() {
493 if (last_added_stream_.get())
494 return last_added_stream_->label();
495 return "";
496 }
497 std::string GetLastRemovedStreamLabel() {
498 if (last_removed_stream_.get())
499 return last_removed_stream_->label();
500 return "";
501 }
502
503 scoped_refptr<PeerConnectionInterface> pc_;
504 PeerConnectionInterface::SignalingState state_;
505 scoped_ptr<IceCandidateInterface> last_candidate_;
506 scoped_refptr<DataChannelInterface> last_datachannel_;
deadbeefab9b2d12015-10-14 11:33:11 -0700507 rtc::scoped_refptr<StreamCollection> remote_streams_;
508 bool renegotiation_needed_ = false;
509 bool ice_complete_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510
511 private:
512 scoped_refptr<MediaStreamInterface> last_added_stream_;
513 scoped_refptr<MediaStreamInterface> last_removed_stream_;
514};
515
516} // namespace
deadbeefab9b2d12015-10-14 11:33:11 -0700517
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518class PeerConnectionInterfaceTest : public testing::Test {
519 protected:
phoglund37ebcf02016-01-08 05:04:57 -0800520 PeerConnectionInterfaceTest() {
521#ifdef WEBRTC_ANDROID
522 webrtc::InitializeAndroidObjects();
523#endif
524 }
525
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 virtual void SetUp() {
527 pc_factory_ = webrtc::CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000528 rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 NULL);
530 ASSERT_TRUE(pc_factory_.get() != NULL);
531 }
532
533 void CreatePeerConnection() {
534 CreatePeerConnection("", "", NULL);
535 }
536
537 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
538 CreatePeerConnection("", "", constraints);
539 }
540
541 void CreatePeerConnection(const std::string& uri,
542 const std::string& password,
543 webrtc::MediaConstraintsInterface* constraints) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800544 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700546 if (!uri.empty()) {
547 server.uri = uri;
548 server.password = password;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800549 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700550 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800552 rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator(
553 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
554 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000555
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +0000556 // DTLS does not work in a loopback call, so is disabled for most of the
557 // tests in this file. We only create a FakeIdentityService if the test
558 // explicitly sets the constraint.
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000559 FakeConstraints default_constraints;
560 if (!constraints) {
561 constraints = &default_constraints;
562
563 default_constraints.AddMandatory(
564 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
565 }
566
Henrik Boström5e56c592015-08-11 10:33:13 +0200567 scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000568 bool dtls;
569 if (FindConstraint(constraints,
570 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
571 &dtls,
Henrik Boström5e56c592015-08-11 10:33:13 +0200572 nullptr) && dtls) {
573 dtls_identity_store.reset(new FakeDtlsIdentityStore());
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000574 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800575 pc_ = pc_factory_->CreatePeerConnection(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800576 config, constraints, std::move(port_allocator),
kwiberg0eb15ed2015-12-17 03:04:15 -0800577 std::move(dtls_identity_store), &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 ASSERT_TRUE(pc_.get() != NULL);
579 observer_.SetPeerConnectionInterface(pc_.get());
580 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
581 }
582
deadbeef0a6c4ca2015-10-06 11:38:28 -0700583 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800584 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700585 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700586 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800587 config.servers.push_back(server);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700588
deadbeef0a6c4ca2015-10-06 11:38:28 -0700589 scoped_refptr<PeerConnectionInterface> pc;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800590 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
591 &observer_);
592 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700593 }
594
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 void CreatePeerConnectionWithDifferentConfigurations() {
596 CreatePeerConnection(kStunAddressOnly, "", NULL);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800597 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
598 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
599 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800601 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602
deadbeef0a6c4ca2015-10-06 11:38:28 -0700603 CreatePeerConnectionExpectFail(kStunInvalidPort);
604 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
605 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
607 CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800608 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
609 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800611 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800613 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800615 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 }
617
618 void ReleasePeerConnection() {
619 pc_ = NULL;
620 observer_.SetPeerConnectionInterface(NULL);
621 }
622
deadbeefab9b2d12015-10-14 11:33:11 -0700623 void AddVideoStream(const std::string& label) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 // Create a local stream.
625 scoped_refptr<MediaStreamInterface> stream(
626 pc_factory_->CreateLocalMediaStream(label));
627 scoped_refptr<VideoSourceInterface> video_source(
628 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
629 scoped_refptr<VideoTrackInterface> video_track(
630 pc_factory_->CreateVideoTrack(label + "v0", video_source));
631 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000632 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
634 observer_.renegotiation_needed_ = false;
635 }
636
637 void AddVoiceStream(const std::string& label) {
638 // Create a local stream.
639 scoped_refptr<MediaStreamInterface> stream(
640 pc_factory_->CreateLocalMediaStream(label));
641 scoped_refptr<AudioTrackInterface> audio_track(
642 pc_factory_->CreateAudioTrack(label + "a0", NULL));
643 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000644 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
646 observer_.renegotiation_needed_ = false;
647 }
648
649 void AddAudioVideoStream(const std::string& stream_label,
650 const std::string& audio_track_label,
651 const std::string& video_track_label) {
652 // Create a local stream.
653 scoped_refptr<MediaStreamInterface> stream(
654 pc_factory_->CreateLocalMediaStream(stream_label));
655 scoped_refptr<AudioTrackInterface> audio_track(
656 pc_factory_->CreateAudioTrack(
657 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
658 stream->AddTrack(audio_track.get());
659 scoped_refptr<VideoTrackInterface> video_track(
660 pc_factory_->CreateVideoTrack(video_track_label, NULL));
661 stream->AddTrack(video_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000662 EXPECT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
664 observer_.renegotiation_needed_ = false;
665 }
666
deadbeefc80741f2015-10-22 13:14:45 -0700667 bool DoCreateOfferAnswer(SessionDescriptionInterface** desc,
668 bool offer,
669 MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000670 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
671 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 MockCreateSessionDescriptionObserver>());
673 if (offer) {
deadbeefc80741f2015-10-22 13:14:45 -0700674 pc_->CreateOffer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 } else {
deadbeefc80741f2015-10-22 13:14:45 -0700676 pc_->CreateAnswer(observer, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 }
678 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
679 *desc = observer->release_desc();
680 return observer->result();
681 }
682
deadbeefc80741f2015-10-22 13:14:45 -0700683 bool DoCreateOffer(SessionDescriptionInterface** desc,
684 MediaConstraintsInterface* constraints) {
685 return DoCreateOfferAnswer(desc, true, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 }
687
deadbeefc80741f2015-10-22 13:14:45 -0700688 bool DoCreateAnswer(SessionDescriptionInterface** desc,
689 MediaConstraintsInterface* constraints) {
690 return DoCreateOfferAnswer(desc, false, constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 }
692
693 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000694 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
695 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 MockSetSessionDescriptionObserver>());
697 if (local) {
698 pc_->SetLocalDescription(observer, desc);
699 } else {
700 pc_->SetRemoteDescription(observer, desc);
701 }
702 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
703 return observer->result();
704 }
705
706 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
707 return DoSetSessionDescription(desc, true);
708 }
709
710 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
711 return DoSetSessionDescription(desc, false);
712 }
713
714 // Calls PeerConnection::GetStats and check the return value.
715 // It does not verify the values in the StatReports since a RTCP packet might
716 // be required.
717 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000718 rtc::scoped_refptr<MockStatsObserver> observer(
719 new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000720 if (!pc_->GetStats(
721 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 return false;
723 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
724 return observer->called();
725 }
726
727 void InitiateCall() {
728 CreatePeerConnection();
729 // Create a local stream with audio&video tracks.
730 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
731 CreateOfferReceiveAnswer();
732 }
733
734 // Verify that RTP Header extensions has been negotiated for audio and video.
735 void VerifyRemoteRtpHeaderExtensions() {
736 const cricket::MediaContentDescription* desc =
737 cricket::GetFirstAudioContentDescription(
738 pc_->remote_description()->description());
739 ASSERT_TRUE(desc != NULL);
740 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
741
742 desc = cricket::GetFirstVideoContentDescription(
743 pc_->remote_description()->description());
744 ASSERT_TRUE(desc != NULL);
745 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
746 }
747
748 void CreateOfferAsRemoteDescription() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000749 rtc::scoped_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -0700750 ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 std::string sdp;
752 EXPECT_TRUE(offer->ToString(&sdp));
753 SessionDescriptionInterface* remote_offer =
754 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
755 sdp, NULL);
756 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
757 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
758 }
759
deadbeefab9b2d12015-10-14 11:33:11 -0700760 void CreateAndSetRemoteOffer(const std::string& sdp) {
761 SessionDescriptionInterface* remote_offer =
762 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
763 sdp, nullptr);
764 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
765 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
766 }
767
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 void CreateAnswerAsLocalDescription() {
769 scoped_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -0700770 ASSERT_TRUE(DoCreateAnswer(answer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771
772 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
773 // audio codec change, even if the parameter has nothing to do with
774 // receiving. Not all parameters are serialized to SDP.
775 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
776 // the SessionDescription, it is necessary to do that here to in order to
777 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
778 // https://code.google.com/p/webrtc/issues/detail?id=1356
779 std::string sdp;
780 EXPECT_TRUE(answer->ToString(&sdp));
781 SessionDescriptionInterface* new_answer =
782 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
783 sdp, NULL);
784 EXPECT_TRUE(DoSetLocalDescription(new_answer));
785 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
786 }
787
788 void CreatePrAnswerAsLocalDescription() {
789 scoped_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -0700790 ASSERT_TRUE(DoCreateAnswer(answer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791
792 std::string sdp;
793 EXPECT_TRUE(answer->ToString(&sdp));
794 SessionDescriptionInterface* pr_answer =
795 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
796 sdp, NULL);
797 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
798 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
799 }
800
801 void CreateOfferReceiveAnswer() {
802 CreateOfferAsLocalDescription();
803 std::string sdp;
804 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
805 CreateAnswerAsRemoteDescription(sdp);
806 }
807
808 void CreateOfferAsLocalDescription() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000809 rtc::scoped_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -0700810 ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
812 // audio codec change, even if the parameter has nothing to do with
813 // receiving. Not all parameters are serialized to SDP.
814 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
815 // the SessionDescription, it is necessary to do that here to in order to
816 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
817 // https://code.google.com/p/webrtc/issues/detail?id=1356
818 std::string sdp;
819 EXPECT_TRUE(offer->ToString(&sdp));
820 SessionDescriptionInterface* new_offer =
821 webrtc::CreateSessionDescription(
822 SessionDescriptionInterface::kOffer,
823 sdp, NULL);
824
825 EXPECT_TRUE(DoSetLocalDescription(new_offer));
826 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +0000827 // Wait for the ice_complete message, so that SDP will have candidates.
828 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 }
830
deadbeefab9b2d12015-10-14 11:33:11 -0700831 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
833 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -0700834 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 EXPECT_TRUE(DoSetRemoteDescription(answer));
836 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
837 }
838
deadbeefab9b2d12015-10-14 11:33:11 -0700839 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 webrtc::JsepSessionDescription* pr_answer =
841 new webrtc::JsepSessionDescription(
842 SessionDescriptionInterface::kPrAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -0700843 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
845 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
846 webrtc::JsepSessionDescription* answer =
847 new webrtc::JsepSessionDescription(
848 SessionDescriptionInterface::kAnswer);
deadbeefab9b2d12015-10-14 11:33:11 -0700849 EXPECT_TRUE(answer->Initialize(sdp, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 EXPECT_TRUE(DoSetRemoteDescription(answer));
851 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
852 }
853
854 // Help function used for waiting until a the last signaled remote stream has
855 // the same label as |stream_label|. In a few of the tests in this file we
856 // answer with the same session description as we offer and thus we can
857 // check if OnAddStream have been called with the same stream as we offer to
858 // send.
859 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
860 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
861 }
862
863 // Creates an offer and applies it as a local session description.
864 // Creates an answer with the same SDP an the offer but removes all lines
865 // that start with a:ssrc"
866 void CreateOfferReceiveAnswerWithoutSsrc() {
867 CreateOfferAsLocalDescription();
868 std::string sdp;
869 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
870 SetSsrcToZero(&sdp);
871 CreateAnswerAsRemoteDescription(sdp);
872 }
873
deadbeefab9b2d12015-10-14 11:33:11 -0700874 // This function creates a MediaStream with label kStreams[0] and
875 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
876 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
877 // is returned in |desc| and the MediaStream is stored in
878 // |reference_collection_|
879 void CreateSessionDescriptionAndReference(
880 size_t number_of_audio_tracks,
881 size_t number_of_video_tracks,
882 SessionDescriptionInterface** desc) {
883 ASSERT_TRUE(desc != nullptr);
884 ASSERT_LE(number_of_audio_tracks, 2u);
885 ASSERT_LE(number_of_video_tracks, 2u);
886
887 reference_collection_ = StreamCollection::Create();
888 std::string sdp_ms1 = std::string(kSdpStringInit);
889
890 std::string mediastream_label = kStreams[0];
891
892 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
893 webrtc::MediaStream::Create(mediastream_label));
894 reference_collection_->AddStream(stream);
895
896 if (number_of_audio_tracks > 0) {
897 sdp_ms1 += std::string(kSdpStringAudio);
898 sdp_ms1 += std::string(kSdpStringMs1Audio0);
899 AddAudioTrack(kAudioTracks[0], stream);
900 }
901 if (number_of_audio_tracks > 1) {
902 sdp_ms1 += kSdpStringMs1Audio1;
903 AddAudioTrack(kAudioTracks[1], stream);
904 }
905
906 if (number_of_video_tracks > 0) {
907 sdp_ms1 += std::string(kSdpStringVideo);
908 sdp_ms1 += std::string(kSdpStringMs1Video0);
909 AddVideoTrack(kVideoTracks[0], stream);
910 }
911 if (number_of_video_tracks > 1) {
912 sdp_ms1 += kSdpStringMs1Video1;
913 AddVideoTrack(kVideoTracks[1], stream);
914 }
915
916 *desc = webrtc::CreateSessionDescription(
917 SessionDescriptionInterface::kOffer, sdp_ms1, nullptr);
918 }
919
920 void AddAudioTrack(const std::string& track_id,
921 MediaStreamInterface* stream) {
922 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
923 webrtc::AudioTrack::Create(track_id, nullptr));
924 ASSERT_TRUE(stream->AddTrack(audio_track));
925 }
926
927 void AddVideoTrack(const std::string& track_id,
928 MediaStreamInterface* stream) {
929 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
930 webrtc::VideoTrack::Create(track_id, nullptr));
931 ASSERT_TRUE(stream->AddTrack(video_track));
932 }
933
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800934 cricket::FakePortAllocator* port_allocator_ = nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
936 scoped_refptr<PeerConnectionInterface> pc_;
937 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -0700938 rtc::scoped_refptr<StreamCollection> reference_collection_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939};
940
941TEST_F(PeerConnectionInterfaceTest,
942 CreatePeerConnectionWithDifferentConfigurations) {
943 CreatePeerConnectionWithDifferentConfigurations();
944}
945
946TEST_F(PeerConnectionInterfaceTest, AddStreams) {
947 CreatePeerConnection();
deadbeefab9b2d12015-10-14 11:33:11 -0700948 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 AddVoiceStream(kStreamLabel2);
950 ASSERT_EQ(2u, pc_->local_streams()->count());
951
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000952 // Test we can add multiple local streams to one peerconnection.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 scoped_refptr<MediaStreamInterface> stream(
954 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
955 scoped_refptr<AudioTrackInterface> audio_track(
956 pc_factory_->CreateAudioTrack(
957 kStreamLabel3, static_cast<AudioSourceInterface*>(NULL)));
958 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +0000959 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000960 EXPECT_EQ(3u, pc_->local_streams()->count());
961
962 // Remove the third stream.
963 pc_->RemoveStream(pc_->local_streams()->at(2));
964 EXPECT_EQ(2u, pc_->local_streams()->count());
965
966 // Remove the second stream.
967 pc_->RemoveStream(pc_->local_streams()->at(1));
968 EXPECT_EQ(1u, pc_->local_streams()->count());
969
970 // Remove the first stream.
971 pc_->RemoveStream(pc_->local_streams()->at(0));
972 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973}
974
deadbeefab9b2d12015-10-14 11:33:11 -0700975// Test that the created offer includes streams we added.
976TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
977 CreatePeerConnection();
978 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
979 scoped_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -0700980 ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -0700981
982 const cricket::ContentInfo* audio_content =
983 cricket::GetFirstAudioContent(offer->description());
984 const cricket::AudioContentDescription* audio_desc =
985 static_cast<const cricket::AudioContentDescription*>(
986 audio_content->description);
987 EXPECT_TRUE(
988 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
989
990 const cricket::ContentInfo* video_content =
991 cricket::GetFirstVideoContent(offer->description());
992 const cricket::VideoContentDescription* video_desc =
993 static_cast<const cricket::VideoContentDescription*>(
994 video_content->description);
995 EXPECT_TRUE(
996 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
997
998 // Add another stream and ensure the offer includes both the old and new
999 // streams.
1000 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
deadbeefc80741f2015-10-22 13:14:45 -07001001 ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001002
1003 audio_content = cricket::GetFirstAudioContent(offer->description());
1004 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1005 audio_content->description);
1006 EXPECT_TRUE(
1007 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1008 EXPECT_TRUE(
1009 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1010
1011 video_content = cricket::GetFirstVideoContent(offer->description());
1012 video_desc = static_cast<const cricket::VideoContentDescription*>(
1013 video_content->description);
1014 EXPECT_TRUE(
1015 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1016 EXPECT_TRUE(
1017 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1018}
1019
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
1021 CreatePeerConnection();
deadbeefab9b2d12015-10-14 11:33:11 -07001022 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 ASSERT_EQ(1u, pc_->local_streams()->count());
1024 pc_->RemoveStream(pc_->local_streams()->at(0));
1025 EXPECT_EQ(0u, pc_->local_streams()->count());
1026}
1027
deadbeefe1f9d832016-01-14 15:35:42 -08001028// Test for AddTrack and RemoveTrack methods.
1029// Tests that the created offer includes tracks we added,
1030// and that the RtpSenders are created correctly.
1031// Also tests that RemoveTrack removes the tracks from subsequent offers.
1032TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
1033 CreatePeerConnection();
1034 // Create a dummy stream, so tracks share a stream label.
1035 scoped_refptr<MediaStreamInterface> stream(
1036 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1037 std::vector<MediaStreamInterface*> stream_list;
1038 stream_list.push_back(stream.get());
1039 scoped_refptr<AudioTrackInterface> audio_track(
1040 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1041 scoped_refptr<VideoTrackInterface> video_track(
1042 pc_factory_->CreateVideoTrack("video_track", nullptr));
1043 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1044 auto video_sender = pc_->AddTrack(video_track, stream_list);
1045 EXPECT_EQ(kStreamLabel1, audio_sender->stream_id());
1046 EXPECT_EQ("audio_track", audio_sender->id());
1047 EXPECT_EQ(audio_track, audio_sender->track());
1048 EXPECT_EQ(kStreamLabel1, video_sender->stream_id());
1049 EXPECT_EQ("video_track", video_sender->id());
1050 EXPECT_EQ(video_track, video_sender->track());
1051
1052 // Now create an offer and check for the senders.
1053 scoped_ptr<SessionDescriptionInterface> offer;
1054 ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr));
1055
1056 const cricket::ContentInfo* audio_content =
1057 cricket::GetFirstAudioContent(offer->description());
1058 const cricket::AudioContentDescription* audio_desc =
1059 static_cast<const cricket::AudioContentDescription*>(
1060 audio_content->description);
1061 EXPECT_TRUE(
1062 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1063
1064 const cricket::ContentInfo* video_content =
1065 cricket::GetFirstVideoContent(offer->description());
1066 const cricket::VideoContentDescription* video_desc =
1067 static_cast<const cricket::VideoContentDescription*>(
1068 video_content->description);
1069 EXPECT_TRUE(
1070 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1071
1072 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1073
1074 // Now try removing the tracks.
1075 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1076 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1077
1078 // Create a new offer and ensure it doesn't contain the removed senders.
1079 ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr));
1080
1081 audio_content = cricket::GetFirstAudioContent(offer->description());
1082 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1083 audio_content->description);
1084 EXPECT_FALSE(
1085 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1086
1087 video_content = cricket::GetFirstVideoContent(offer->description());
1088 video_desc = static_cast<const cricket::VideoContentDescription*>(
1089 video_content->description);
1090 EXPECT_FALSE(
1091 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1092
1093 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1094
1095 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1096 // should return false.
1097 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1098 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1099}
1100
1101// Test creating senders without a stream specified,
1102// expecting a random stream ID to be generated.
1103TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
1104 CreatePeerConnection();
1105 // Create a dummy stream, so tracks share a stream label.
1106 scoped_refptr<AudioTrackInterface> audio_track(
1107 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1108 scoped_refptr<VideoTrackInterface> video_track(
1109 pc_factory_->CreateVideoTrack("video_track", nullptr));
1110 auto audio_sender =
1111 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1112 auto video_sender =
1113 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1114 EXPECT_EQ("audio_track", audio_sender->id());
1115 EXPECT_EQ(audio_track, audio_sender->track());
1116 EXPECT_EQ("video_track", video_sender->id());
1117 EXPECT_EQ(video_track, video_sender->track());
1118 // If the ID is truly a random GUID, it should be infinitely unlikely they
1119 // will be the same.
1120 EXPECT_NE(video_sender->stream_id(), audio_sender->stream_id());
1121}
1122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1124 InitiateCall();
1125 WaitAndVerifyOnAddStream(kStreamLabel1);
1126 VerifyRemoteRtpHeaderExtensions();
1127}
1128
1129TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
1130 CreatePeerConnection();
deadbeefab9b2d12015-10-14 11:33:11 -07001131 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 CreateOfferAsLocalDescription();
1133 std::string offer;
1134 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1135 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1136 WaitAndVerifyOnAddStream(kStreamLabel1);
1137}
1138
1139TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
1140 CreatePeerConnection();
deadbeefab9b2d12015-10-14 11:33:11 -07001141 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142
1143 CreateOfferAsRemoteDescription();
1144 CreateAnswerAsLocalDescription();
1145
1146 WaitAndVerifyOnAddStream(kStreamLabel1);
1147}
1148
1149TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
1150 CreatePeerConnection();
deadbeefab9b2d12015-10-14 11:33:11 -07001151 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152
1153 CreateOfferAsRemoteDescription();
1154 CreatePrAnswerAsLocalDescription();
1155 CreateAnswerAsLocalDescription();
1156
1157 WaitAndVerifyOnAddStream(kStreamLabel1);
1158}
1159
1160TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1161 InitiateCall();
1162 ASSERT_EQ(1u, pc_->remote_streams()->count());
1163 pc_->RemoveStream(pc_->local_streams()->at(0));
1164 CreateOfferReceiveAnswer();
1165 EXPECT_EQ(0u, pc_->remote_streams()->count());
deadbeefab9b2d12015-10-14 11:33:11 -07001166 AddVideoStream(kStreamLabel1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 CreateOfferReceiveAnswer();
1168}
1169
1170// Tests that after negotiating an audio only call, the respondent can perform a
1171// renegotiation that removes the audio stream.
1172TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
1173 CreatePeerConnection();
1174 AddVoiceStream(kStreamLabel1);
1175 CreateOfferAsRemoteDescription();
1176 CreateAnswerAsLocalDescription();
1177
1178 ASSERT_EQ(1u, pc_->remote_streams()->count());
1179 pc_->RemoveStream(pc_->local_streams()->at(0));
1180 CreateOfferReceiveAnswer();
1181 EXPECT_EQ(0u, pc_->remote_streams()->count());
1182}
1183
1184// Test that candidates are generated and that we can parse our own candidates.
1185TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
1186 CreatePeerConnection();
1187
1188 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1189 // SetRemoteDescription takes ownership of offer.
1190 SessionDescriptionInterface* offer = NULL;
deadbeefab9b2d12015-10-14 11:33:11 -07001191 AddVideoStream(kStreamLabel1);
deadbeefc80741f2015-10-22 13:14:45 -07001192 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 EXPECT_TRUE(DoSetRemoteDescription(offer));
1194
1195 // SetLocalDescription takes ownership of answer.
1196 SessionDescriptionInterface* answer = NULL;
deadbeefc80741f2015-10-22 13:14:45 -07001197 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 EXPECT_TRUE(DoSetLocalDescription(answer));
1199
1200 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1201 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1202
1203 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1204}
1205
deadbeefab9b2d12015-10-14 11:33:11 -07001206// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207// not unique.
1208TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
1209 CreatePeerConnection();
1210 // Create a regular offer for the CreateAnswer test later.
1211 SessionDescriptionInterface* offer = NULL;
deadbeefc80741f2015-10-22 13:14:45 -07001212 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 EXPECT_TRUE(offer != NULL);
1214 delete offer;
1215 offer = NULL;
1216
1217 // Create a local stream with audio&video tracks having same label.
1218 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1219
1220 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001221 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222
1223 // Test CreateAnswer
1224 SessionDescriptionInterface* answer = NULL;
deadbeefc80741f2015-10-22 13:14:45 -07001225 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226}
1227
1228// Test that we will get different SSRCs for each tracks in the offer and answer
1229// we created.
1230TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
1231 CreatePeerConnection();
1232 // Create a local stream with audio&video tracks having different labels.
1233 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1234
1235 // Test CreateOffer
1236 scoped_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001237 ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 int audio_ssrc = 0;
1239 int video_ssrc = 0;
1240 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1241 &audio_ssrc));
1242 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1243 &video_ssrc));
1244 EXPECT_NE(audio_ssrc, video_ssrc);
1245
1246 // Test CreateAnswer
1247 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
1248 scoped_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001249 ASSERT_TRUE(DoCreateAnswer(answer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 audio_ssrc = 0;
1251 video_ssrc = 0;
1252 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1253 &audio_ssrc));
1254 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1255 &video_ssrc));
1256 EXPECT_NE(audio_ssrc, video_ssrc);
1257}
1258
deadbeefeb459812015-12-15 19:24:43 -08001259// Test that it's possible to call AddTrack on a MediaStream after adding
1260// the stream to a PeerConnection.
1261// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1262TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
1263 CreatePeerConnection();
1264 // Create audio stream and add to PeerConnection.
1265 AddVoiceStream(kStreamLabel1);
1266 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1267
1268 // Add video track to the audio-only stream.
1269 scoped_refptr<VideoTrackInterface> video_track(
1270 pc_factory_->CreateVideoTrack("video_label", nullptr));
1271 stream->AddTrack(video_track.get());
1272
1273 scoped_ptr<SessionDescriptionInterface> offer;
1274 ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr));
1275
1276 const cricket::MediaContentDescription* video_desc =
1277 cricket::GetFirstVideoContentDescription(offer->description());
1278 EXPECT_TRUE(video_desc != nullptr);
1279}
1280
1281// Test that it's possible to call RemoveTrack on a MediaStream after adding
1282// the stream to a PeerConnection.
1283// TODO(deadbeef): Remove this test once this behavior is no longer supported.
1284TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
1285 CreatePeerConnection();
1286 // Create audio/video stream and add to PeerConnection.
1287 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1288 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1289
1290 // Remove the video track.
1291 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1292
1293 scoped_ptr<SessionDescriptionInterface> offer;
1294 ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr));
1295
1296 const cricket::MediaContentDescription* video_desc =
1297 cricket::GetFirstVideoContentDescription(offer->description());
1298 EXPECT_TRUE(video_desc == nullptr);
1299}
1300
deadbeefbd7d8f72015-12-18 16:58:44 -08001301// Test creating a sender with a stream ID, and ensure the ID is populated
1302// in the offer.
1303TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
1304 CreatePeerConnection();
1305 pc_->CreateSender("video", kStreamLabel1);
1306
1307 scoped_ptr<SessionDescriptionInterface> offer;
1308 ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr));
1309
1310 const cricket::MediaContentDescription* video_desc =
1311 cricket::GetFirstVideoContentDescription(offer->description());
1312 ASSERT_TRUE(video_desc != nullptr);
1313 ASSERT_EQ(1u, video_desc->streams().size());
1314 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1315}
1316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317// Test that we can specify a certain track that we want statistics about.
1318TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1319 InitiateCall();
1320 ASSERT_LT(0u, pc_->remote_streams()->count());
1321 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
1322 scoped_refptr<MediaStreamTrackInterface> remote_audio =
1323 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1324 EXPECT_TRUE(DoGetStats(remote_audio));
1325
1326 // Remove the stream. Since we are sending to our selves the local
1327 // and the remote stream is the same.
1328 pc_->RemoveStream(pc_->local_streams()->at(0));
1329 // Do a re-negotiation.
1330 CreateOfferReceiveAnswer();
1331
1332 ASSERT_EQ(0u, pc_->remote_streams()->count());
1333
1334 // Test that we still can get statistics for the old track. Even if it is not
1335 // sent any longer.
1336 EXPECT_TRUE(DoGetStats(remote_audio));
1337}
1338
1339// Test that we can get stats on a video track.
1340TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1341 InitiateCall();
1342 ASSERT_LT(0u, pc_->remote_streams()->count());
1343 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
1344 scoped_refptr<MediaStreamTrackInterface> remote_video =
1345 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1346 EXPECT_TRUE(DoGetStats(remote_video));
1347}
1348
1349// Test that we don't get statistics for an invalid track.
tommi@webrtc.org908f57e2014-07-21 11:44:39 +00001350// TODO(tommi): Fix this test. DoGetStats will return true
1351// for the unknown track (since GetStats is async), but no
1352// data is returned for the track.
1353TEST_F(PeerConnectionInterfaceTest, DISABLED_GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 InitiateCall();
1355 scoped_refptr<AudioTrackInterface> unknown_audio_track(
1356 pc_factory_->CreateAudioTrack("unknown track", NULL));
1357 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1358}
1359
1360// This test setup two RTP data channels in loop back.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 FakeConstraints constraints;
1363 constraints.SetAllowRtpDataChannels();
1364 CreatePeerConnection(&constraints);
1365 scoped_refptr<DataChannelInterface> data1 =
1366 pc_->CreateDataChannel("test1", NULL);
1367 scoped_refptr<DataChannelInterface> data2 =
1368 pc_->CreateDataChannel("test2", NULL);
1369 ASSERT_TRUE(data1 != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001370 rtc::scoped_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 new MockDataChannelObserver(data1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001372 rtc::scoped_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 new MockDataChannelObserver(data2));
1374
1375 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1376 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1377 std::string data_to_send1 = "testing testing";
1378 std::string data_to_send2 = "testing something else";
1379 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1380
1381 CreateOfferReceiveAnswer();
1382 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1383 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1384
1385 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1386 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1387 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1388 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1389
1390 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1391 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1392
1393 data1->Close();
1394 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1395 CreateOfferReceiveAnswer();
1396 EXPECT_FALSE(observer1->IsOpen());
1397 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1398 EXPECT_TRUE(observer2->IsOpen());
1399
1400 data_to_send2 = "testing something else again";
1401 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1402
1403 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1404}
1405
1406// This test verifies that sendnig binary data over RTP data channels should
1407// fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 FakeConstraints constraints;
1410 constraints.SetAllowRtpDataChannels();
1411 CreatePeerConnection(&constraints);
1412 scoped_refptr<DataChannelInterface> data1 =
1413 pc_->CreateDataChannel("test1", NULL);
1414 scoped_refptr<DataChannelInterface> data2 =
1415 pc_->CreateDataChannel("test2", NULL);
1416 ASSERT_TRUE(data1 != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001417 rtc::scoped_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 new MockDataChannelObserver(data1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001419 rtc::scoped_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 new MockDataChannelObserver(data2));
1421
1422 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1423 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1424
1425 CreateOfferReceiveAnswer();
1426 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1427 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1428
1429 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1430 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1431
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001432 rtc::Buffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1434}
1435
1436// This test setup a RTP data channels in loop back and test that a channel is
1437// opened even if the remote end answer with a zero SSRC.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 FakeConstraints constraints;
1440 constraints.SetAllowRtpDataChannels();
1441 CreatePeerConnection(&constraints);
1442 scoped_refptr<DataChannelInterface> data1 =
1443 pc_->CreateDataChannel("test1", NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001444 rtc::scoped_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445 new MockDataChannelObserver(data1));
1446
1447 CreateOfferReceiveAnswerWithoutSsrc();
1448
1449 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1450
1451 data1->Close();
1452 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1453 CreateOfferReceiveAnswerWithoutSsrc();
1454 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1455 EXPECT_FALSE(observer1->IsOpen());
1456}
1457
1458// This test that if a data channel is added in an answer a receive only channel
1459// channel is created.
1460TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1461 FakeConstraints constraints;
1462 constraints.SetAllowRtpDataChannels();
1463 CreatePeerConnection(&constraints);
1464
1465 std::string offer_label = "offer_channel";
1466 scoped_refptr<DataChannelInterface> offer_channel =
1467 pc_->CreateDataChannel(offer_label, NULL);
1468
1469 CreateOfferAsLocalDescription();
1470
1471 // Replace the data channel label in the offer and apply it as an answer.
1472 std::string receive_label = "answer_channel";
1473 std::string sdp;
1474 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001475 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 receive_label.c_str(), receive_label.length(),
1477 &sdp);
1478 CreateAnswerAsRemoteDescription(sdp);
1479
1480 // Verify that a new incoming data channel has been created and that
1481 // it is open but can't we written to.
1482 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1483 DataChannelInterface* received_channel = observer_.last_datachannel_;
1484 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1485 EXPECT_EQ(receive_label, received_channel->label());
1486 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1487
1488 // Verify that the channel we initially offered has been rejected.
1489 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1490
1491 // Do another offer / answer exchange and verify that the data channel is
1492 // opened.
1493 CreateOfferReceiveAnswer();
1494 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1495 kTimeout);
1496}
1497
1498// This test that no data channel is returned if a reliable channel is
1499// requested.
1500// TODO(perkj): Remove this test once reliable channels are implemented.
1501TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1502 FakeConstraints constraints;
1503 constraints.SetAllowRtpDataChannels();
1504 CreatePeerConnection(&constraints);
1505
1506 std::string label = "test";
1507 webrtc::DataChannelInit config;
1508 config.reliable = true;
1509 scoped_refptr<DataChannelInterface> channel =
1510 pc_->CreateDataChannel(label, &config);
1511 EXPECT_TRUE(channel == NULL);
1512}
1513
deadbeefab9b2d12015-10-14 11:33:11 -07001514// Verifies that duplicated label is not allowed for RTP data channel.
1515TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1516 FakeConstraints constraints;
1517 constraints.SetAllowRtpDataChannels();
1518 CreatePeerConnection(&constraints);
1519
1520 std::string label = "test";
1521 scoped_refptr<DataChannelInterface> channel =
1522 pc_->CreateDataChannel(label, nullptr);
1523 EXPECT_NE(channel, nullptr);
1524
1525 scoped_refptr<DataChannelInterface> dup_channel =
1526 pc_->CreateDataChannel(label, nullptr);
1527 EXPECT_EQ(dup_channel, nullptr);
1528}
1529
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530// This tests that a SCTP data channel is returned using different
1531// DataChannelInit configurations.
1532TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1533 FakeConstraints constraints;
1534 constraints.SetAllowDtlsSctpDataChannels();
1535 CreatePeerConnection(&constraints);
1536
1537 webrtc::DataChannelInit config;
1538
1539 scoped_refptr<DataChannelInterface> channel =
1540 pc_->CreateDataChannel("1", &config);
1541 EXPECT_TRUE(channel != NULL);
1542 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001543 EXPECT_TRUE(observer_.renegotiation_needed_);
1544 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545
1546 config.ordered = false;
1547 channel = pc_->CreateDataChannel("2", &config);
1548 EXPECT_TRUE(channel != NULL);
1549 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001550 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551
1552 config.ordered = true;
1553 config.maxRetransmits = 0;
1554 channel = pc_->CreateDataChannel("3", &config);
1555 EXPECT_TRUE(channel != NULL);
1556 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001557 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558
1559 config.maxRetransmits = -1;
1560 config.maxRetransmitTime = 0;
1561 channel = pc_->CreateDataChannel("4", &config);
1562 EXPECT_TRUE(channel != NULL);
1563 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001564 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565}
1566
1567// This tests that no data channel is returned if both maxRetransmits and
1568// maxRetransmitTime are set for SCTP data channels.
1569TEST_F(PeerConnectionInterfaceTest,
1570 CreateSctpDataChannelShouldFailForInvalidConfig) {
1571 FakeConstraints constraints;
1572 constraints.SetAllowDtlsSctpDataChannels();
1573 CreatePeerConnection(&constraints);
1574
1575 std::string label = "test";
1576 webrtc::DataChannelInit config;
1577 config.maxRetransmits = 0;
1578 config.maxRetransmitTime = 0;
1579
1580 scoped_refptr<DataChannelInterface> channel =
1581 pc_->CreateDataChannel(label, &config);
1582 EXPECT_TRUE(channel == NULL);
1583}
1584
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585// The test verifies that creating a SCTP data channel with an id already in use
1586// or out of range should fail.
1587TEST_F(PeerConnectionInterfaceTest,
1588 CreateSctpDataChannelWithInvalidIdShouldFail) {
1589 FakeConstraints constraints;
1590 constraints.SetAllowDtlsSctpDataChannels();
1591 CreatePeerConnection(&constraints);
1592
1593 webrtc::DataChannelInit config;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001594 scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001596 config.id = 1;
1597 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 EXPECT_TRUE(channel != NULL);
1599 EXPECT_EQ(1, channel->id());
1600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 channel = pc_->CreateDataChannel("x", &config);
1602 EXPECT_TRUE(channel == NULL);
1603
1604 config.id = cricket::kMaxSctpSid;
1605 channel = pc_->CreateDataChannel("max", &config);
1606 EXPECT_TRUE(channel != NULL);
1607 EXPECT_EQ(config.id, channel->id());
1608
1609 config.id = cricket::kMaxSctpSid + 1;
1610 channel = pc_->CreateDataChannel("x", &config);
1611 EXPECT_TRUE(channel == NULL);
1612}
1613
deadbeefab9b2d12015-10-14 11:33:11 -07001614// Verifies that duplicated label is allowed for SCTP data channel.
1615TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
1616 FakeConstraints constraints;
1617 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1618 true);
1619 CreatePeerConnection(&constraints);
1620
1621 std::string label = "test";
1622 scoped_refptr<DataChannelInterface> channel =
1623 pc_->CreateDataChannel(label, nullptr);
1624 EXPECT_NE(channel, nullptr);
1625
1626 scoped_refptr<DataChannelInterface> dup_channel =
1627 pc_->CreateDataChannel(label, nullptr);
1628 EXPECT_NE(dup_channel, nullptr);
1629}
1630
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001631// This test verifies that OnRenegotiationNeeded is fired for every new RTP
1632// DataChannel.
1633TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
1634 FakeConstraints constraints;
1635 constraints.SetAllowRtpDataChannels();
1636 CreatePeerConnection(&constraints);
1637
1638 scoped_refptr<DataChannelInterface> dc1 =
1639 pc_->CreateDataChannel("test1", NULL);
1640 EXPECT_TRUE(observer_.renegotiation_needed_);
1641 observer_.renegotiation_needed_ = false;
1642
1643 scoped_refptr<DataChannelInterface> dc2 =
1644 pc_->CreateDataChannel("test2", NULL);
1645 EXPECT_TRUE(observer_.renegotiation_needed_);
1646}
1647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648// This test that a data channel closes when a PeerConnection is deleted/closed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 FakeConstraints constraints;
1651 constraints.SetAllowRtpDataChannels();
1652 CreatePeerConnection(&constraints);
1653
1654 scoped_refptr<DataChannelInterface> data1 =
1655 pc_->CreateDataChannel("test1", NULL);
1656 scoped_refptr<DataChannelInterface> data2 =
1657 pc_->CreateDataChannel("test2", NULL);
1658 ASSERT_TRUE(data1 != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001659 rtc::scoped_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 new MockDataChannelObserver(data1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001661 rtc::scoped_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 new MockDataChannelObserver(data2));
1663
1664 CreateOfferReceiveAnswer();
1665 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1666 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1667
1668 ReleasePeerConnection();
1669 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1670 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
1671}
1672
1673// This test that data channels can be rejected in an answer.
1674TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
1675 FakeConstraints constraints;
1676 constraints.SetAllowRtpDataChannels();
1677 CreatePeerConnection(&constraints);
1678
1679 scoped_refptr<DataChannelInterface> offer_channel(
1680 pc_->CreateDataChannel("offer_channel", NULL));
1681
1682 CreateOfferAsLocalDescription();
1683
1684 // Create an answer where the m-line for data channels are rejected.
1685 std::string sdp;
1686 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1687 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1688 SessionDescriptionInterface::kAnswer);
1689 EXPECT_TRUE(answer->Initialize(sdp, NULL));
1690 cricket::ContentInfo* data_info =
1691 answer->description()->GetContentByName("data");
1692 data_info->rejected = true;
1693
1694 DoSetRemoteDescription(answer);
1695 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1696}
1697
1698// Test that we can create a session description from an SDP string from
1699// FireFox, use it as a remote session description, generate an answer and use
1700// the answer as a local description.
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001701TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001702 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 FakeConstraints constraints;
1704 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1705 true);
1706 CreatePeerConnection(&constraints);
1707 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1708 SessionDescriptionInterface* desc =
1709 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07001710 webrtc::kFireFoxSdpOffer, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 EXPECT_TRUE(DoSetSessionDescription(desc, false));
1712 CreateAnswerAsLocalDescription();
1713 ASSERT_TRUE(pc_->local_description() != NULL);
1714 ASSERT_TRUE(pc_->remote_description() != NULL);
1715
1716 const cricket::ContentInfo* content =
1717 cricket::GetFirstAudioContent(pc_->local_description()->description());
1718 ASSERT_TRUE(content != NULL);
1719 EXPECT_FALSE(content->rejected);
1720
1721 content =
1722 cricket::GetFirstVideoContent(pc_->local_description()->description());
1723 ASSERT_TRUE(content != NULL);
1724 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001725#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 content =
1727 cricket::GetFirstDataContent(pc_->local_description()->description());
1728 ASSERT_TRUE(content != NULL);
1729 EXPECT_TRUE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00001730#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731}
1732
1733// Test that we can create an audio only offer and receive an answer with a
1734// limited set of audio codecs and receive an updated offer with more audio
1735// codecs, where the added codecs are not supported.
1736TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
1737 CreatePeerConnection();
1738 AddVoiceStream("audio_label");
1739 CreateOfferAsLocalDescription();
1740
1741 SessionDescriptionInterface* answer =
1742 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
jbauchfabe2c92015-07-16 13:43:14 -07001743 webrtc::kAudioSdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 EXPECT_TRUE(DoSetSessionDescription(answer, false));
1745
1746 SessionDescriptionInterface* updated_offer =
1747 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
jbauchfabe2c92015-07-16 13:43:14 -07001748 webrtc::kAudioSdpWithUnsupportedCodecs,
1749 nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
1751 CreateAnswerAsLocalDescription();
1752}
1753
deadbeefc80741f2015-10-22 13:14:45 -07001754// Test that if we're receiving (but not sending) a track, subsequent offers
1755// will have m-lines with a=recvonly.
1756TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
1757 FakeConstraints constraints;
1758 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1759 true);
1760 CreatePeerConnection(&constraints);
1761 CreateAndSetRemoteOffer(kSdpStringWithStream1);
1762 CreateAnswerAsLocalDescription();
1763
1764 // At this point we should be receiving stream 1, but not sending anything.
1765 // A new offer should be recvonly.
1766 SessionDescriptionInterface* offer;
1767 DoCreateOffer(&offer, nullptr);
1768
1769 const cricket::ContentInfo* video_content =
1770 cricket::GetFirstVideoContent(offer->description());
1771 const cricket::VideoContentDescription* video_desc =
1772 static_cast<const cricket::VideoContentDescription*>(
1773 video_content->description);
1774 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
1775
1776 const cricket::ContentInfo* audio_content =
1777 cricket::GetFirstAudioContent(offer->description());
1778 const cricket::AudioContentDescription* audio_desc =
1779 static_cast<const cricket::AudioContentDescription*>(
1780 audio_content->description);
1781 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
1782}
1783
1784// Test that if we're receiving (but not sending) a track, and the
1785// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
1786// false, the generated m-lines will be a=inactive.
1787TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
1788 FakeConstraints constraints;
1789 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1790 true);
1791 CreatePeerConnection(&constraints);
1792 CreateAndSetRemoteOffer(kSdpStringWithStream1);
1793 CreateAnswerAsLocalDescription();
1794
1795 // At this point we should be receiving stream 1, but not sending anything.
1796 // A new offer would be recvonly, but we'll set the "no receive" constraints
1797 // to make it inactive.
1798 SessionDescriptionInterface* offer;
1799 FakeConstraints offer_constraints;
1800 offer_constraints.AddMandatory(
1801 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
1802 offer_constraints.AddMandatory(
1803 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
1804 DoCreateOffer(&offer, &offer_constraints);
1805
1806 const cricket::ContentInfo* video_content =
1807 cricket::GetFirstVideoContent(offer->description());
1808 const cricket::VideoContentDescription* video_desc =
1809 static_cast<const cricket::VideoContentDescription*>(
1810 video_content->description);
1811 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
1812
1813 const cricket::ContentInfo* audio_content =
1814 cricket::GetFirstAudioContent(offer->description());
1815 const cricket::AudioContentDescription* audio_desc =
1816 static_cast<const cricket::AudioContentDescription*>(
1817 audio_content->description);
1818 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
1819}
1820
deadbeef653b8e02015-11-11 12:55:10 -08001821// Test that we can use SetConfiguration to change the ICE servers of the
1822// PortAllocator.
1823TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
1824 CreatePeerConnection();
1825
1826 PeerConnectionInterface::RTCConfiguration config;
1827 PeerConnectionInterface::IceServer server;
1828 server.uri = "stun:test_hostname";
1829 config.servers.push_back(server);
1830 EXPECT_TRUE(pc_->SetConfiguration(config));
1831
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001832 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
1833 EXPECT_EQ("test_hostname",
1834 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08001835}
1836
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837// Test that PeerConnection::Close changes the states to closed and all remote
1838// tracks change state to ended.
1839TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
1840 // Initialize a PeerConnection and negotiate local and remote session
1841 // description.
1842 InitiateCall();
1843 ASSERT_EQ(1u, pc_->local_streams()->count());
1844 ASSERT_EQ(1u, pc_->remote_streams()->count());
1845
1846 pc_->Close();
1847
1848 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
1849 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
1850 pc_->ice_connection_state());
1851 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
1852 pc_->ice_gathering_state());
1853
1854 EXPECT_EQ(1u, pc_->local_streams()->count());
1855 EXPECT_EQ(1u, pc_->remote_streams()->count());
1856
1857 scoped_refptr<MediaStreamInterface> remote_stream =
1858 pc_->remote_streams()->at(0);
1859 EXPECT_EQ(MediaStreamTrackInterface::kEnded,
1860 remote_stream->GetVideoTracks()[0]->state());
1861 EXPECT_EQ(MediaStreamTrackInterface::kEnded,
1862 remote_stream->GetAudioTracks()[0]->state());
1863}
1864
1865// Test that PeerConnection methods fails gracefully after
1866// PeerConnection::Close has been called.
1867TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
1868 CreatePeerConnection();
1869 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1870 CreateOfferAsRemoteDescription();
1871 CreateAnswerAsLocalDescription();
1872
1873 ASSERT_EQ(1u, pc_->local_streams()->count());
1874 scoped_refptr<MediaStreamInterface> local_stream =
1875 pc_->local_streams()->at(0);
1876
1877 pc_->Close();
1878
1879 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001880 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881
1882 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001883 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
wu@webrtc.org66037362013-08-13 00:09:35 +00001885 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886
1887 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
1888
1889 EXPECT_TRUE(pc_->local_description() != NULL);
1890 EXPECT_TRUE(pc_->remote_description() != NULL);
1891
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001892 rtc::scoped_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001893 EXPECT_TRUE(DoCreateOffer(offer.use(), nullptr));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001894 rtc::scoped_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001895 EXPECT_TRUE(DoCreateAnswer(answer.use(), nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896
1897 std::string sdp;
1898 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
1899 SessionDescriptionInterface* remote_offer =
1900 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1901 sdp, NULL);
1902 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
1903
1904 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
1905 SessionDescriptionInterface* local_offer =
1906 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1907 sdp, NULL);
1908 EXPECT_FALSE(DoSetLocalDescription(local_offer));
1909}
1910
1911// Test that GetStats can still be called after PeerConnection::Close.
1912TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
1913 InitiateCall();
1914 pc_->Close();
1915 DoGetStats(NULL);
1916}
deadbeefab9b2d12015-10-14 11:33:11 -07001917
1918// NOTE: The series of tests below come from what used to be
1919// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
1920// setting a remote or local description has the expected effects.
1921
1922// This test verifies that the remote MediaStreams corresponding to a received
1923// SDP string is created. In this test the two separate MediaStreams are
1924// signaled.
1925TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
1926 FakeConstraints constraints;
1927 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1928 true);
1929 CreatePeerConnection(&constraints);
1930 CreateAndSetRemoteOffer(kSdpStringWithStream1);
1931
1932 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1));
1933 EXPECT_TRUE(
1934 CompareStreamCollections(observer_.remote_streams(), reference.get()));
1935 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
1936 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
1937
1938 // Create a session description based on another SDP with another
1939 // MediaStream.
1940 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
1941
1942 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2));
1943 EXPECT_TRUE(
1944 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
1945}
1946
1947// This test verifies that when remote tracks are added/removed from SDP, the
1948// created remote streams are updated appropriately.
1949TEST_F(PeerConnectionInterfaceTest,
1950 AddRemoveTrackFromExistingRemoteMediaStream) {
1951 FakeConstraints constraints;
1952 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1953 true);
1954 CreatePeerConnection(&constraints);
1955 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1;
1956 CreateSessionDescriptionAndReference(1, 1, desc_ms1.accept());
1957 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
1958 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1959 reference_collection_));
1960
1961 // Add extra audio and video tracks to the same MediaStream.
1962 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks;
1963 CreateSessionDescriptionAndReference(2, 2, desc_ms1_two_tracks.accept());
1964 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
1965 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1966 reference_collection_));
1967
1968 // Remove the extra audio and video tracks.
1969 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2;
1970 CreateSessionDescriptionAndReference(1, 1, desc_ms2.accept());
1971 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
1972 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1973 reference_collection_));
1974}
1975
1976// This tests that remote tracks are ended if a local session description is set
1977// that rejects the media content type.
1978TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
1979 FakeConstraints constraints;
1980 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1981 true);
1982 CreatePeerConnection(&constraints);
1983 // First create and set a remote offer, then reject its video content in our
1984 // answer.
1985 CreateAndSetRemoteOffer(kSdpStringWithStream1);
1986 ASSERT_EQ(1u, observer_.remote_streams()->count());
1987 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
1988 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
1989 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
1990
1991 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
1992 remote_stream->GetVideoTracks()[0];
1993 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
1994 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
1995 remote_stream->GetAudioTracks()[0];
1996 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
1997
1998 rtc::scoped_ptr<SessionDescriptionInterface> local_answer;
deadbeefc80741f2015-10-22 13:14:45 -07001999 EXPECT_TRUE(DoCreateAnswer(local_answer.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002000 cricket::ContentInfo* video_info =
2001 local_answer->description()->GetContentByName("video");
2002 video_info->rejected = true;
2003 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2004 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2005 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2006
2007 // Now create an offer where we reject both video and audio.
2008 rtc::scoped_ptr<SessionDescriptionInterface> local_offer;
deadbeefc80741f2015-10-22 13:14:45 -07002009 EXPECT_TRUE(DoCreateOffer(local_offer.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002010 video_info = local_offer->description()->GetContentByName("video");
2011 ASSERT_TRUE(video_info != nullptr);
2012 video_info->rejected = true;
2013 cricket::ContentInfo* audio_info =
2014 local_offer->description()->GetContentByName("audio");
2015 ASSERT_TRUE(audio_info != nullptr);
2016 audio_info->rejected = true;
2017 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
2018 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2019 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_audio->state());
2020}
2021
2022// This tests that we won't crash if the remote track has been removed outside
2023// of PeerConnection and then PeerConnection tries to reject the track.
2024TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2025 FakeConstraints constraints;
2026 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2027 true);
2028 CreatePeerConnection(&constraints);
2029 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2030 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2031 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2032 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2033
2034 rtc::scoped_ptr<SessionDescriptionInterface> local_answer(
2035 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2036 kSdpStringWithStream1, nullptr));
2037 cricket::ContentInfo* video_info =
2038 local_answer->description()->GetContentByName("video");
2039 video_info->rejected = true;
2040 cricket::ContentInfo* audio_info =
2041 local_answer->description()->GetContentByName("audio");
2042 audio_info->rejected = true;
2043 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2044
2045 // No crash is a pass.
2046}
2047
deadbeef5e97fb52015-10-15 12:49:08 -07002048// This tests that if a recvonly remote description is set, no remote streams
2049// will be created, even if the description contains SSRCs/MSIDs.
2050// See: https://code.google.com/p/webrtc/issues/detail?id=5054
2051TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2052 FakeConstraints constraints;
2053 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2054 true);
2055 CreatePeerConnection(&constraints);
2056
2057 std::string recvonly_offer = kSdpStringWithStream1;
2058 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2059 strlen(kRecvonly), &recvonly_offer);
2060 CreateAndSetRemoteOffer(recvonly_offer);
2061
2062 EXPECT_EQ(0u, observer_.remote_streams()->count());
2063}
2064
deadbeefab9b2d12015-10-14 11:33:11 -07002065// This tests that a default MediaStream is created if a remote session
2066// description doesn't contain any streams and no MSID support.
2067// It also tests that the default stream is updated if a video m-line is added
2068// in a subsequent session description.
2069TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
2070 FakeConstraints constraints;
2071 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2072 true);
2073 CreatePeerConnection(&constraints);
2074 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2075
2076 ASSERT_EQ(1u, observer_.remote_streams()->count());
2077 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2078
2079 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2080 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2081 EXPECT_EQ("default", remote_stream->label());
2082
2083 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2084 ASSERT_EQ(1u, observer_.remote_streams()->count());
2085 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2086 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
2087 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2088 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
2089}
2090
2091// This tests that a default MediaStream is created if a remote session
2092// description doesn't contain any streams and media direction is send only.
2093TEST_F(PeerConnectionInterfaceTest,
2094 SendOnlySdpWithoutMsidCreatesDefaultStream) {
2095 FakeConstraints constraints;
2096 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2097 true);
2098 CreatePeerConnection(&constraints);
2099 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2100
2101 ASSERT_EQ(1u, observer_.remote_streams()->count());
2102 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2103
2104 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2105 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2106 EXPECT_EQ("default", remote_stream->label());
2107}
2108
2109// This tests that it won't crash when PeerConnection tries to remove
2110// a remote track that as already been removed from the MediaStream.
2111TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2112 FakeConstraints constraints;
2113 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2114 true);
2115 CreatePeerConnection(&constraints);
2116 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2117 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2118 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2119 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2120
2121 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2122
2123 // No crash is a pass.
2124}
2125
2126// This tests that a default MediaStream is created if the remote session
2127// description doesn't contain any streams and don't contain an indication if
2128// MSID is supported.
2129TEST_F(PeerConnectionInterfaceTest,
2130 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
2131 FakeConstraints constraints;
2132 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2133 true);
2134 CreatePeerConnection(&constraints);
2135 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2136
2137 ASSERT_EQ(1u, observer_.remote_streams()->count());
2138 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2139 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2140 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2141}
2142
2143// This tests that a default MediaStream is not created if the remote session
2144// description doesn't contain any streams but does support MSID.
2145TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
2146 FakeConstraints constraints;
2147 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2148 true);
2149 CreatePeerConnection(&constraints);
2150 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2151 EXPECT_EQ(0u, observer_.remote_streams()->count());
2152}
2153
deadbeefbda7e0b2015-12-08 17:13:40 -08002154// This tests that when setting a new description, the old default tracks are
2155// not destroyed and recreated.
2156// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
2157TEST_F(PeerConnectionInterfaceTest, DefaultTracksNotDestroyedAndRecreated) {
2158 FakeConstraints constraints;
2159 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2160 true);
2161 CreatePeerConnection(&constraints);
2162 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2163
2164 ASSERT_EQ(1u, observer_.remote_streams()->count());
2165 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2166 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2167
2168 // Set the track to "disabled", then set a new description and ensure the
2169 // track is still disabled, which ensures it hasn't been recreated.
2170 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2171 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2172 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2173 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2174}
2175
deadbeefab9b2d12015-10-14 11:33:11 -07002176// This tests that a default MediaStream is not created if a remote session
2177// description is updated to not have any MediaStreams.
2178TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2179 FakeConstraints constraints;
2180 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2181 true);
2182 CreatePeerConnection(&constraints);
2183 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2184 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1));
2185 EXPECT_TRUE(
2186 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2187
2188 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2189 EXPECT_EQ(0u, observer_.remote_streams()->count());
2190}
2191
2192// This tests that an RtpSender is created when the local description is set
2193// after adding a local stream.
2194// TODO(deadbeef): This test and the one below it need to be updated when
2195// an RtpSender's lifetime isn't determined by when a local description is set.
2196TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
2197 FakeConstraints constraints;
2198 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2199 true);
2200 CreatePeerConnection(&constraints);
2201 // Create an offer just to ensure we have an identity before we manually
2202 // call SetLocalDescription.
2203 rtc::scoped_ptr<SessionDescriptionInterface> throwaway;
deadbeefc80741f2015-10-22 13:14:45 -07002204 ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002205
2206 rtc::scoped_ptr<SessionDescriptionInterface> desc_1;
2207 CreateSessionDescriptionAndReference(2, 2, desc_1.accept());
2208
2209 pc_->AddStream(reference_collection_->at(0));
2210 EXPECT_TRUE(DoSetLocalDescription(desc_1.release()));
2211 auto senders = pc_->GetSenders();
2212 EXPECT_EQ(4u, senders.size());
2213 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2214 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2215 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2216 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2217
2218 // Remove an audio and video track.
deadbeeffac06552015-11-25 11:26:01 -08002219 pc_->RemoveStream(reference_collection_->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002220 rtc::scoped_ptr<SessionDescriptionInterface> desc_2;
2221 CreateSessionDescriptionAndReference(1, 1, desc_2.accept());
deadbeeffac06552015-11-25 11:26:01 -08002222 pc_->AddStream(reference_collection_->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002223 EXPECT_TRUE(DoSetLocalDescription(desc_2.release()));
2224 senders = pc_->GetSenders();
2225 EXPECT_EQ(2u, senders.size());
2226 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2227 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2228 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2229 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2230}
2231
2232// This tests that an RtpSender is created when the local description is set
2233// before adding a local stream.
2234TEST_F(PeerConnectionInterfaceTest,
2235 AddLocalStreamAfterLocalDescriptionChanged) {
2236 FakeConstraints constraints;
2237 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2238 true);
2239 CreatePeerConnection(&constraints);
2240 // Create an offer just to ensure we have an identity before we manually
2241 // call SetLocalDescription.
2242 rtc::scoped_ptr<SessionDescriptionInterface> throwaway;
deadbeefc80741f2015-10-22 13:14:45 -07002243 ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002244
2245 rtc::scoped_ptr<SessionDescriptionInterface> desc_1;
2246 CreateSessionDescriptionAndReference(2, 2, desc_1.accept());
2247
2248 EXPECT_TRUE(DoSetLocalDescription(desc_1.release()));
2249 auto senders = pc_->GetSenders();
2250 EXPECT_EQ(0u, senders.size());
2251
2252 pc_->AddStream(reference_collection_->at(0));
2253 senders = pc_->GetSenders();
2254 EXPECT_EQ(4u, senders.size());
2255 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2256 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2257 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2258 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2259}
2260
2261// This tests that the expected behavior occurs if the SSRC on a local track is
2262// changed when SetLocalDescription is called.
2263TEST_F(PeerConnectionInterfaceTest,
2264 ChangeSsrcOnTrackInLocalSessionDescription) {
2265 FakeConstraints constraints;
2266 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2267 true);
2268 CreatePeerConnection(&constraints);
2269 // Create an offer just to ensure we have an identity before we manually
2270 // call SetLocalDescription.
2271 rtc::scoped_ptr<SessionDescriptionInterface> throwaway;
deadbeefc80741f2015-10-22 13:14:45 -07002272 ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002273
2274 rtc::scoped_ptr<SessionDescriptionInterface> desc;
2275 CreateSessionDescriptionAndReference(1, 1, desc.accept());
2276 std::string sdp;
2277 desc->ToString(&sdp);
2278
2279 pc_->AddStream(reference_collection_->at(0));
2280 EXPECT_TRUE(DoSetLocalDescription(desc.release()));
2281 auto senders = pc_->GetSenders();
2282 EXPECT_EQ(2u, senders.size());
2283 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2284 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2285
2286 // Change the ssrc of the audio and video track.
2287 std::string ssrc_org = "a=ssrc:1";
2288 std::string ssrc_to = "a=ssrc:97";
2289 rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(),
2290 ssrc_to.length(), &sdp);
2291 ssrc_org = "a=ssrc:2";
2292 ssrc_to = "a=ssrc:98";
2293 rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(),
2294 ssrc_to.length(), &sdp);
2295 rtc::scoped_ptr<SessionDescriptionInterface> updated_desc(
2296 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp,
2297 nullptr));
2298
2299 EXPECT_TRUE(DoSetLocalDescription(updated_desc.release()));
2300 senders = pc_->GetSenders();
2301 EXPECT_EQ(2u, senders.size());
2302 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2303 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2304 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2305 // changed.
2306}
2307
2308// This tests that the expected behavior occurs if a new session description is
2309// set with the same tracks, but on a different MediaStream.
2310TEST_F(PeerConnectionInterfaceTest, SignalSameTracksInSeparateMediaStream) {
2311 FakeConstraints constraints;
2312 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2313 true);
2314 CreatePeerConnection(&constraints);
2315 // Create an offer just to ensure we have an identity before we manually
2316 // call SetLocalDescription.
2317 rtc::scoped_ptr<SessionDescriptionInterface> throwaway;
deadbeefc80741f2015-10-22 13:14:45 -07002318 ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002319
2320 rtc::scoped_ptr<SessionDescriptionInterface> desc;
2321 CreateSessionDescriptionAndReference(1, 1, desc.accept());
2322 std::string sdp;
2323 desc->ToString(&sdp);
2324
2325 pc_->AddStream(reference_collection_->at(0));
2326 EXPECT_TRUE(DoSetLocalDescription(desc.release()));
2327 auto senders = pc_->GetSenders();
2328 EXPECT_EQ(2u, senders.size());
2329 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2330 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2331
2332 // Add a new MediaStream but with the same tracks as in the first stream.
2333 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2334 webrtc::MediaStream::Create(kStreams[1]));
2335 stream_1->AddTrack(reference_collection_->at(0)->GetVideoTracks()[0]);
2336 stream_1->AddTrack(reference_collection_->at(0)->GetAudioTracks()[0]);
2337 pc_->AddStream(stream_1);
2338
2339 // Replace msid in the original SDP.
2340 rtc::replace_substrs(kStreams[0], strlen(kStreams[0]), kStreams[1],
2341 strlen(kStreams[1]), &sdp);
2342
2343 rtc::scoped_ptr<SessionDescriptionInterface> updated_desc(
2344 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp,
2345 nullptr));
2346
2347 EXPECT_TRUE(DoSetLocalDescription(updated_desc.release()));
2348 senders = pc_->GetSenders();
2349 EXPECT_EQ(2u, senders.size());
2350 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2351 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2352}
2353
2354// The following tests verify that session options are created correctly.
deadbeefc80741f2015-10-22 13:14:45 -07002355// TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
2356// "verify options are converted correctly", should be "pass options into
2357// CreateOffer and verify the correct offer is produced."
deadbeefab9b2d12015-10-14 11:33:11 -07002358
2359TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
2360 RTCOfferAnswerOptions rtc_options;
2361 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
2362
2363 cricket::MediaSessionOptions options;
2364 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options));
2365
2366 rtc_options.offer_to_receive_audio =
2367 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
2368 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options));
2369}
2370
2371TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
2372 RTCOfferAnswerOptions rtc_options;
2373 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
2374
2375 cricket::MediaSessionOptions options;
2376 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options));
2377
2378 rtc_options.offer_to_receive_video =
2379 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
2380 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options));
2381}
2382
2383// Test that a MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07002384// OfferToReceiveAudio and OfferToReceiveVideo options are set.
deadbeefab9b2d12015-10-14 11:33:11 -07002385TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
2386 RTCOfferAnswerOptions rtc_options;
2387 rtc_options.offer_to_receive_audio = 1;
2388 rtc_options.offer_to_receive_video = 1;
2389
2390 cricket::MediaSessionOptions options;
2391 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
2392 EXPECT_TRUE(options.has_audio());
2393 EXPECT_TRUE(options.has_video());
2394 EXPECT_TRUE(options.bundle_enabled);
2395}
2396
2397// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07002398// OfferToReceiveAudio is set.
deadbeefab9b2d12015-10-14 11:33:11 -07002399TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
2400 RTCOfferAnswerOptions rtc_options;
2401 rtc_options.offer_to_receive_audio = 1;
2402
2403 cricket::MediaSessionOptions options;
2404 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
2405 EXPECT_TRUE(options.has_audio());
2406 EXPECT_FALSE(options.has_video());
2407 EXPECT_TRUE(options.bundle_enabled);
2408}
2409
2410// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07002411// the default OfferOptions are used.
deadbeefab9b2d12015-10-14 11:33:11 -07002412TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
2413 RTCOfferAnswerOptions rtc_options;
2414
2415 cricket::MediaSessionOptions options;
2416 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
deadbeefc80741f2015-10-22 13:14:45 -07002417 EXPECT_TRUE(options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07002418 EXPECT_FALSE(options.has_video());
deadbeefc80741f2015-10-22 13:14:45 -07002419 EXPECT_TRUE(options.bundle_enabled);
deadbeefab9b2d12015-10-14 11:33:11 -07002420 EXPECT_TRUE(options.vad_enabled);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002421 EXPECT_FALSE(options.audio_transport_options.ice_restart);
2422 EXPECT_FALSE(options.video_transport_options.ice_restart);
2423 EXPECT_FALSE(options.data_transport_options.ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07002424}
2425
2426// Test that a correct MediaSessionOptions is created for an offer if
deadbeefc80741f2015-10-22 13:14:45 -07002427// OfferToReceiveVideo is set.
deadbeefab9b2d12015-10-14 11:33:11 -07002428TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
2429 RTCOfferAnswerOptions rtc_options;
2430 rtc_options.offer_to_receive_audio = 0;
2431 rtc_options.offer_to_receive_video = 1;
2432
2433 cricket::MediaSessionOptions options;
2434 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
2435 EXPECT_FALSE(options.has_audio());
2436 EXPECT_TRUE(options.has_video());
2437 EXPECT_TRUE(options.bundle_enabled);
2438}
2439
2440// Test that a correct MediaSessionOptions is created for an offer if
2441// UseRtpMux is set to false.
2442TEST(CreateSessionOptionsTest,
2443 GetMediaSessionOptionsForOfferWithBundleDisabled) {
2444 RTCOfferAnswerOptions rtc_options;
2445 rtc_options.offer_to_receive_audio = 1;
2446 rtc_options.offer_to_receive_video = 1;
2447 rtc_options.use_rtp_mux = false;
2448
2449 cricket::MediaSessionOptions options;
2450 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
2451 EXPECT_TRUE(options.has_audio());
2452 EXPECT_TRUE(options.has_video());
2453 EXPECT_FALSE(options.bundle_enabled);
2454}
2455
2456// Test that a correct MediaSessionOptions is created to restart ice if
2457// IceRestart is set. It also tests that subsequent MediaSessionOptions don't
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002458// have |audio_transport_options.ice_restart| etc. set.
deadbeefab9b2d12015-10-14 11:33:11 -07002459TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
2460 RTCOfferAnswerOptions rtc_options;
2461 rtc_options.ice_restart = true;
2462
2463 cricket::MediaSessionOptions options;
2464 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002465 EXPECT_TRUE(options.audio_transport_options.ice_restart);
2466 EXPECT_TRUE(options.video_transport_options.ice_restart);
2467 EXPECT_TRUE(options.data_transport_options.ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07002468
2469 rtc_options = RTCOfferAnswerOptions();
2470 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options));
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002471 EXPECT_FALSE(options.audio_transport_options.ice_restart);
2472 EXPECT_FALSE(options.video_transport_options.ice_restart);
2473 EXPECT_FALSE(options.data_transport_options.ice_restart);
deadbeefab9b2d12015-10-14 11:33:11 -07002474}
2475
2476// Test that the MediaConstraints in an answer don't affect if audio and video
2477// is offered in an offer but that if kOfferToReceiveAudio or
2478// kOfferToReceiveVideo constraints are true in an offer, the media type will be
2479// included in subsequent answers.
2480TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
2481 FakeConstraints answer_c;
2482 answer_c.SetMandatoryReceiveAudio(true);
2483 answer_c.SetMandatoryReceiveVideo(true);
2484
2485 cricket::MediaSessionOptions answer_options;
2486 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
2487 EXPECT_TRUE(answer_options.has_audio());
2488 EXPECT_TRUE(answer_options.has_video());
2489
deadbeefc80741f2015-10-22 13:14:45 -07002490 RTCOfferAnswerOptions rtc_offer_options;
deadbeefab9b2d12015-10-14 11:33:11 -07002491
2492 cricket::MediaSessionOptions offer_options;
deadbeefc80741f2015-10-22 13:14:45 -07002493 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_offer_options, &offer_options));
2494 EXPECT_TRUE(offer_options.has_audio());
deadbeefab9b2d12015-10-14 11:33:11 -07002495 EXPECT_FALSE(offer_options.has_video());
2496
deadbeefc80741f2015-10-22 13:14:45 -07002497 RTCOfferAnswerOptions updated_rtc_offer_options;
2498 updated_rtc_offer_options.offer_to_receive_audio = 1;
2499 updated_rtc_offer_options.offer_to_receive_video = 1;
deadbeefab9b2d12015-10-14 11:33:11 -07002500
2501 cricket::MediaSessionOptions updated_offer_options;
deadbeefc80741f2015-10-22 13:14:45 -07002502 EXPECT_TRUE(ConvertRtcOptionsForOffer(updated_rtc_offer_options,
deadbeefab9b2d12015-10-14 11:33:11 -07002503 &updated_offer_options));
2504 EXPECT_TRUE(updated_offer_options.has_audio());
2505 EXPECT_TRUE(updated_offer_options.has_video());
2506
2507 // Since an offer has been created with both audio and video, subsequent
2508 // offers and answers should contain both audio and video.
2509 // Answers will only contain the media types that exist in the offer
2510 // regardless of the value of |updated_answer_options.has_audio| and
2511 // |updated_answer_options.has_video|.
2512 FakeConstraints updated_answer_c;
2513 answer_c.SetMandatoryReceiveAudio(false);
2514 answer_c.SetMandatoryReceiveVideo(false);
2515
2516 cricket::MediaSessionOptions updated_answer_options;
2517 EXPECT_TRUE(
2518 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2519 EXPECT_TRUE(updated_answer_options.has_audio());
2520 EXPECT_TRUE(updated_answer_options.has_video());
deadbeefab9b2d12015-10-14 11:33:11 -07002521}