Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: webrtc/api/peerconnectioninterface_unittest.cc

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Big move! Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12 #include <string>
13 #include <utility>
14
15 #include "webrtc/api/audiotrack.h"
16 #include "webrtc/api/jsepsessiondescription.h"
17 #include "webrtc/api/mediastream.h"
18 #include "webrtc/api/mediastreaminterface.h"
19 #include "webrtc/api/peerconnection.h"
20 #include "webrtc/api/peerconnectioninterface.h"
21 #include "webrtc/api/rtpreceiverinterface.h"
22 #include "webrtc/api/rtpsenderinterface.h"
23 #include "webrtc/api/streamcollection.h"
24 #include "webrtc/api/test/fakeconstraints.h"
25 #include "webrtc/api/test/fakertccertificategenerator.h"
26 #include "webrtc/api/test/fakevideotracksource.h"
27 #include "webrtc/api/test/mockpeerconnectionobservers.h"
28 #include "webrtc/api/test/testsdpstrings.h"
29 #include "webrtc/api/videocapturertracksource.h"
30 #include "webrtc/api/videotrack.h"
31 #include "webrtc/base/gunit.h"
32 #include "webrtc/base/ssladapter.h"
33 #include "webrtc/base/sslstreamadapter.h"
34 #include "webrtc/base/stringutils.h"
35 #include "webrtc/base/thread.h"
36 #include "webrtc/media/base/fakevideocapturer.h"
37 #include "webrtc/media/sctp/sctpdataengine.h"
38 #include "webrtc/p2p/base/fakeportallocator.h"
39 #include "webrtc/p2p/base/faketransportcontroller.h"
40 #include "webrtc/pc/mediasession.h"
41 #include "webrtc/test/gmock.h"
42
43 #ifdef WEBRTC_ANDROID
44 #include "webrtc/api/test/androidtestinitializer.h"
45 #endif
46
47 static const char kStreamLabel1[] = "local_stream_1";
48 static const char kStreamLabel2[] = "local_stream_2";
49 static const char kStreamLabel3[] = "local_stream_3";
50 static const int kDefaultStunPort = 3478;
51 static const char kStunAddressOnly[] = "stun:address";
52 static const char kStunInvalidPort[] = "stun:address:-1";
53 static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
54 static const char kStunAddressPortAndMore2[] = "stun:address:port more";
55 static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
56 static const char kTurnUsername[] = "user";
57 static const char kTurnPassword[] = "password";
58 static const char kTurnHostname[] = "turn.example.org";
59 static const uint32_t kTimeout = 10000U;
60
61 static const char kStreams[][8] = {"stream1", "stream2"};
62 static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
63 static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
64
65 static const char kRecvonly[] = "recvonly";
66 static const char kSendrecv[] = "sendrecv";
67
68 // Reference SDP with a MediaStream with label "stream1" and audio track with
69 // id "audio_1" and a video track with id "video_1;
70 static const char kSdpStringWithStream1[] =
71 "v=0\r\n"
72 "o=- 0 0 IN IP4 127.0.0.1\r\n"
73 "s=-\r\n"
74 "t=0 0\r\n"
75 "a=ice-ufrag:e5785931\r\n"
76 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
77 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
78 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
79 "m=audio 1 RTP/AVPF 103\r\n"
80 "a=mid:audio\r\n"
81 "a=sendrecv\r\n"
82 "a=rtpmap:103 ISAC/16000\r\n"
83 "a=ssrc:1 cname:stream1\r\n"
84 "a=ssrc:1 mslabel:stream1\r\n"
85 "a=ssrc:1 label:audiotrack0\r\n"
86 "m=video 1 RTP/AVPF 120\r\n"
87 "a=mid:video\r\n"
88 "a=sendrecv\r\n"
89 "a=rtpmap:120 VP8/90000\r\n"
90 "a=ssrc:2 cname:stream1\r\n"
91 "a=ssrc:2 mslabel:stream1\r\n"
92 "a=ssrc:2 label:videotrack0\r\n";
93
94 // Reference SDP with a MediaStream with label "stream1" and audio track with
95 // id "audio_1";
96 static const char kSdpStringWithStream1AudioTrackOnly[] =
97 "v=0\r\n"
98 "o=- 0 0 IN IP4 127.0.0.1\r\n"
99 "s=-\r\n"
100 "t=0 0\r\n"
101 "a=ice-ufrag:e5785931\r\n"
102 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
103 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
104 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
105 "m=audio 1 RTP/AVPF 103\r\n"
106 "a=mid:audio\r\n"
107 "a=sendrecv\r\n"
108 "a=rtpmap:103 ISAC/16000\r\n"
109 "a=ssrc:1 cname:stream1\r\n"
110 "a=ssrc:1 mslabel:stream1\r\n"
111 "a=ssrc:1 label:audiotrack0\r\n";
112
113 // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
114 // MediaStreams have one audio track and one video track.
115 // This uses MSID.
116 static const char kSdpStringWithStream1And2[] =
117 "v=0\r\n"
118 "o=- 0 0 IN IP4 127.0.0.1\r\n"
119 "s=-\r\n"
120 "t=0 0\r\n"
121 "a=ice-ufrag:e5785931\r\n"
122 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
123 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
124 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
125 "a=msid-semantic: WMS stream1 stream2\r\n"
126 "m=audio 1 RTP/AVPF 103\r\n"
127 "a=mid:audio\r\n"
128 "a=sendrecv\r\n"
129 "a=rtpmap:103 ISAC/16000\r\n"
130 "a=ssrc:1 cname:stream1\r\n"
131 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
132 "a=ssrc:3 cname:stream2\r\n"
133 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
134 "m=video 1 RTP/AVPF 120\r\n"
135 "a=mid:video\r\n"
136 "a=sendrecv\r\n"
137 "a=rtpmap:120 VP8/0\r\n"
138 "a=ssrc:2 cname:stream1\r\n"
139 "a=ssrc:2 msid:stream1 videotrack0\r\n"
140 "a=ssrc:4 cname:stream2\r\n"
141 "a=ssrc:4 msid:stream2 videotrack1\r\n";
142
143 // Reference SDP without MediaStreams. Msid is not supported.
144 static const char kSdpStringWithoutStreams[] =
145 "v=0\r\n"
146 "o=- 0 0 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
149 "a=ice-ufrag:e5785931\r\n"
150 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
151 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
152 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
153 "m=audio 1 RTP/AVPF 103\r\n"
154 "a=mid:audio\r\n"
155 "a=sendrecv\r\n"
156 "a=rtpmap:103 ISAC/16000\r\n"
157 "m=video 1 RTP/AVPF 120\r\n"
158 "a=mid:video\r\n"
159 "a=sendrecv\r\n"
160 "a=rtpmap:120 VP8/90000\r\n";
161
162 // Reference SDP without MediaStreams. Msid is supported.
163 static const char kSdpStringWithMsidWithoutStreams[] =
164 "v=0\r\n"
165 "o=- 0 0 IN IP4 127.0.0.1\r\n"
166 "s=-\r\n"
167 "t=0 0\r\n"
168 "a=ice-ufrag:e5785931\r\n"
169 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
170 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
171 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
172 "a=msid-semantic: WMS\r\n"
173 "m=audio 1 RTP/AVPF 103\r\n"
174 "a=mid:audio\r\n"
175 "a=sendrecv\r\n"
176 "a=rtpmap:103 ISAC/16000\r\n"
177 "m=video 1 RTP/AVPF 120\r\n"
178 "a=mid:video\r\n"
179 "a=sendrecv\r\n"
180 "a=rtpmap:120 VP8/90000\r\n";
181
182 // Reference SDP without MediaStreams and audio only.
183 static const char kSdpStringWithoutStreamsAudioOnly[] =
184 "v=0\r\n"
185 "o=- 0 0 IN IP4 127.0.0.1\r\n"
186 "s=-\r\n"
187 "t=0 0\r\n"
188 "a=ice-ufrag:e5785931\r\n"
189 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
190 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
191 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
192 "m=audio 1 RTP/AVPF 103\r\n"
193 "a=mid:audio\r\n"
194 "a=sendrecv\r\n"
195 "a=rtpmap:103 ISAC/16000\r\n";
196
197 // Reference SENDONLY SDP without MediaStreams. Msid is not supported.
198 static const char kSdpStringSendOnlyWithoutStreams[] =
199 "v=0\r\n"
200 "o=- 0 0 IN IP4 127.0.0.1\r\n"
201 "s=-\r\n"
202 "t=0 0\r\n"
203 "a=ice-ufrag:e5785931\r\n"
204 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
205 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
206 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
207 "m=audio 1 RTP/AVPF 103\r\n"
208 "a=mid:audio\r\n"
209 "a=sendrecv\r\n"
210 "a=sendonly\r\n"
211 "a=rtpmap:103 ISAC/16000\r\n"
212 "m=video 1 RTP/AVPF 120\r\n"
213 "a=mid:video\r\n"
214 "a=sendrecv\r\n"
215 "a=sendonly\r\n"
216 "a=rtpmap:120 VP8/90000\r\n";
217
218 static const char kSdpStringInit[] =
219 "v=0\r\n"
220 "o=- 0 0 IN IP4 127.0.0.1\r\n"
221 "s=-\r\n"
222 "t=0 0\r\n"
223 "a=ice-ufrag:e5785931\r\n"
224 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
225 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
226 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
227 "a=msid-semantic: WMS\r\n";
228
229 static const char kSdpStringAudio[] =
230 "m=audio 1 RTP/AVPF 103\r\n"
231 "a=mid:audio\r\n"
232 "a=sendrecv\r\n"
233 "a=rtpmap:103 ISAC/16000\r\n";
234
235 static const char kSdpStringVideo[] =
236 "m=video 1 RTP/AVPF 120\r\n"
237 "a=mid:video\r\n"
238 "a=sendrecv\r\n"
239 "a=rtpmap:120 VP8/90000\r\n";
240
241 static const char kSdpStringMs1Audio0[] =
242 "a=ssrc:1 cname:stream1\r\n"
243 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
244
245 static const char kSdpStringMs1Video0[] =
246 "a=ssrc:2 cname:stream1\r\n"
247 "a=ssrc:2 msid:stream1 videotrack0\r\n";
248
249 static const char kSdpStringMs1Audio1[] =
250 "a=ssrc:3 cname:stream1\r\n"
251 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
252
253 static const char kSdpStringMs1Video1[] =
254 "a=ssrc:4 cname:stream1\r\n"
255 "a=ssrc:4 msid:stream1 videotrack1\r\n";
256
257 #define MAYBE_SKIP_TEST(feature) \
258 if (!(feature())) { \
259 LOG(LS_INFO) << "Feature disabled... skipping"; \
260 return; \
261 }
262
263 using ::testing::Exactly;
264 using cricket::StreamParams;
265 using webrtc::AudioSourceInterface;
266 using webrtc::AudioTrack;
267 using webrtc::AudioTrackInterface;
268 using webrtc::DataBuffer;
269 using webrtc::DataChannelInterface;
270 using webrtc::FakeConstraints;
271 using webrtc::IceCandidateInterface;
272 using webrtc::JsepSessionDescription;
273 using webrtc::MediaConstraintsInterface;
274 using webrtc::MediaStream;
275 using webrtc::MediaStreamInterface;
276 using webrtc::MediaStreamTrackInterface;
277 using webrtc::MockCreateSessionDescriptionObserver;
278 using webrtc::MockDataChannelObserver;
279 using webrtc::MockSetSessionDescriptionObserver;
280 using webrtc::MockStatsObserver;
281 using webrtc::NotifierInterface;
282 using webrtc::ObserverInterface;
283 using webrtc::PeerConnectionInterface;
284 using webrtc::PeerConnectionObserver;
285 using webrtc::RtpReceiverInterface;
286 using webrtc::RtpSenderInterface;
287 using webrtc::SdpParseError;
288 using webrtc::SessionDescriptionInterface;
289 using webrtc::StreamCollection;
290 using webrtc::StreamCollectionInterface;
291 using webrtc::VideoTrackSourceInterface;
292 using webrtc::VideoTrack;
293 using webrtc::VideoTrackInterface;
294
295 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
296
297 namespace {
298
299 // Gets the first ssrc of given content type from the ContentInfo.
300 bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
301 if (!content_info || !ssrc) {
302 return false;
303 }
304 const cricket::MediaContentDescription* media_desc =
305 static_cast<const cricket::MediaContentDescription*>(
306 content_info->description);
307 if (!media_desc || media_desc->streams().empty()) {
308 return false;
309 }
310 *ssrc = media_desc->streams().begin()->first_ssrc();
311 return true;
312 }
313
314 void SetSsrcToZero(std::string* sdp) {
315 const char kSdpSsrcAtribute[] = "a=ssrc:";
316 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
317 size_t ssrc_pos = 0;
318 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
319 std::string::npos) {
320 size_t end_ssrc = sdp->find(" ", ssrc_pos);
321 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
322 ssrc_pos = end_ssrc;
323 }
324 }
325
326 // Check if |streams| contains the specified track.
327 bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
328 const std::string& stream_label,
329 const std::string& track_id) {
330 for (const cricket::StreamParams& params : streams) {
331 if (params.sync_label == stream_label && params.id == track_id) {
332 return true;
333 }
334 }
335 return false;
336 }
337
338 // Check if |senders| contains the specified sender, by id.
339 bool ContainsSender(
340 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
341 const std::string& id) {
342 for (const auto& sender : senders) {
343 if (sender->id() == id) {
344 return true;
345 }
346 }
347 return false;
348 }
349
350 // Check if |senders| contains the specified sender, by id and stream id.
351 bool ContainsSender(
352 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
353 const std::string& id,
354 const std::string& stream_id) {
355 for (const auto& sender : senders) {
356 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
357 return true;
358 }
359 }
360 return false;
361 }
362
363 // Create a collection of streams.
364 // CreateStreamCollection(1) creates a collection that
365 // correspond to kSdpStringWithStream1.
366 // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
367 rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
368 int number_of_streams,
369 int tracks_per_stream) {
370 rtc::scoped_refptr<StreamCollection> local_collection(
371 StreamCollection::Create());
372
373 for (int i = 0; i < number_of_streams; ++i) {
374 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
375 webrtc::MediaStream::Create(kStreams[i]));
376
377 for (int j = 0; j < tracks_per_stream; ++j) {
378 // Add a local audio track.
379 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
380 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
381 nullptr));
382 stream->AddTrack(audio_track);
383
384 // Add a local video track.
385 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
386 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
387 webrtc::FakeVideoTrackSource::Create()));
388 stream->AddTrack(video_track);
389 }
390
391 local_collection->AddStream(stream);
392 }
393 return local_collection;
394 }
395
396 // Check equality of StreamCollections.
397 bool CompareStreamCollections(StreamCollectionInterface* s1,
398 StreamCollectionInterface* s2) {
399 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
400 return false;
401 }
402
403 for (size_t i = 0; i != s1->count(); ++i) {
404 if (s1->at(i)->label() != s2->at(i)->label()) {
405 return false;
406 }
407 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
408 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
409 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
410 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
411
412 if (audio_tracks1.size() != audio_tracks2.size()) {
413 return false;
414 }
415 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
416 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
417 return false;
418 }
419 }
420 if (video_tracks1.size() != video_tracks2.size()) {
421 return false;
422 }
423 for (size_t j = 0; j != video_tracks1.size(); ++j) {
424 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
425 return false;
426 }
427 }
428 }
429 return true;
430 }
431
432 // Helper class to test Observer.
433 class MockTrackObserver : public ObserverInterface {
434 public:
435 explicit MockTrackObserver(NotifierInterface* notifier)
436 : notifier_(notifier) {
437 notifier_->RegisterObserver(this);
438 }
439
440 ~MockTrackObserver() { Unregister(); }
441
442 void Unregister() {
443 if (notifier_) {
444 notifier_->UnregisterObserver(this);
445 notifier_ = nullptr;
446 }
447 }
448
449 MOCK_METHOD0(OnChanged, void());
450
451 private:
452 NotifierInterface* notifier_;
453 };
454
455 class MockPeerConnectionObserver : public PeerConnectionObserver {
456 public:
457 // We need these using declarations because there are two versions of each of
458 // the below methods and we only override one of them.
459 // TODO(deadbeef): Remove once there's only one version of the methods.
460 using PeerConnectionObserver::OnAddStream;
461 using PeerConnectionObserver::OnRemoveStream;
462 using PeerConnectionObserver::OnDataChannel;
463
464 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
465 virtual ~MockPeerConnectionObserver() {
466 }
467 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
468 pc_ = pc;
469 if (pc) {
470 state_ = pc_->signaling_state();
471 }
472 }
473 void OnSignalingChange(
474 PeerConnectionInterface::SignalingState new_state) override {
475 EXPECT_EQ(pc_->signaling_state(), new_state);
476 state_ = new_state;
477 }
478 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
479 virtual void OnStateChange(StateType state_changed) {
480 if (pc_.get() == NULL)
481 return;
482 switch (state_changed) {
483 case kSignalingState:
484 // OnSignalingChange and OnStateChange(kSignalingState) should always
485 // be called approximately simultaneously. To ease testing, we require
486 // that they always be called in that order. This check verifies
487 // that OnSignalingChange has just been called.
488 EXPECT_EQ(pc_->signaling_state(), state_);
489 break;
490 case kIceState:
491 ADD_FAILURE();
492 break;
493 default:
494 ADD_FAILURE();
495 break;
496 }
497 }
498
499 MediaStreamInterface* RemoteStream(const std::string& label) {
500 return remote_streams_->find(label);
501 }
502 StreamCollectionInterface* remote_streams() const { return remote_streams_; }
503 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override {
504 last_added_stream_ = stream;
505 remote_streams_->AddStream(stream);
506 }
507 void OnRemoveStream(
508 rtc::scoped_refptr<MediaStreamInterface> stream) override {
509 last_removed_stream_ = stream;
510 remote_streams_->RemoveStream(stream);
511 }
512 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; }
513 void OnDataChannel(
514 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
515 last_datachannel_ = data_channel;
516 }
517
518 void OnIceConnectionChange(
519 PeerConnectionInterface::IceConnectionState new_state) override {
520 EXPECT_EQ(pc_->ice_connection_state(), new_state);
521 callback_triggered_ = true;
522 }
523 void OnIceGatheringChange(
524 PeerConnectionInterface::IceGatheringState new_state) override {
525 EXPECT_EQ(pc_->ice_gathering_state(), new_state);
526 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete;
527 callback_triggered_ = true;
528 }
529 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
530 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
531 pc_->ice_gathering_state());
532
533 std::string sdp;
534 EXPECT_TRUE(candidate->ToString(&sdp));
535 EXPECT_LT(0u, sdp.size());
536 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(),
537 candidate->sdp_mline_index(), sdp, NULL));
538 EXPECT_TRUE(last_candidate_.get() != NULL);
539 callback_triggered_ = true;
540 }
541
542 void OnIceCandidatesRemoved(
543 const std::vector<cricket::Candidate>& candidates) override {
544 callback_triggered_ = true;
545 }
546
547 void OnIceConnectionReceivingChange(bool receiving) override {
548 callback_triggered_ = true;
549 }
550
551 void OnAddTrack(rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
552 std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>
553 streams) override {
554 EXPECT_TRUE(receiver != nullptr);
555 num_added_tracks_++;
556 last_added_track_label_ = receiver->id();
557 }
558
559 // Returns the label of the last added stream.
560 // Empty string if no stream have been added.
561 std::string GetLastAddedStreamLabel() {
562 if (last_added_stream_.get())
563 return last_added_stream_->label();
564 return "";
565 }
566 std::string GetLastRemovedStreamLabel() {
567 if (last_removed_stream_.get())
568 return last_removed_stream_->label();
569 return "";
570 }
571
572 rtc::scoped_refptr<PeerConnectionInterface> pc_;
573 PeerConnectionInterface::SignalingState state_;
574 std::unique_ptr<IceCandidateInterface> last_candidate_;
575 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
576 rtc::scoped_refptr<StreamCollection> remote_streams_;
577 bool renegotiation_needed_ = false;
578 bool ice_complete_ = false;
579 bool callback_triggered_ = false;
580 int num_added_tracks_ = 0;
581 std::string last_added_track_label_;
582
583 private:
584 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
585 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
586 };
587
588 } // namespace
589
590 // The PeerConnectionMediaConfig tests below verify that configuration
591 // and constraints are propagated into the MediaConfig passed to
592 // CreateMediaController. These settings are intended for MediaChannel
593 // constructors, but that is not exercised by these unittest.
594 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
595 public:
596 webrtc::MediaControllerInterface* CreateMediaController(
597 const cricket::MediaConfig& config,
598 webrtc::RtcEventLog* event_log) const override {
599 create_media_controller_called_ = true;
600 create_media_controller_config_ = config;
601
602 webrtc::MediaControllerInterface* mc =
603 PeerConnectionFactory::CreateMediaController(config, event_log);
604 EXPECT_TRUE(mc != nullptr);
605 return mc;
606 }
607
608 cricket::TransportController* CreateTransportController(
609 cricket::PortAllocator* port_allocator,
610 bool redetermine_role_on_ice_restart) override {
611 transport_controller = new cricket::TransportController(
612 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator,
613 redetermine_role_on_ice_restart);
614 return transport_controller;
615 }
616
617 cricket::TransportController* transport_controller;
618 // Mutable, so they can be modified in the above const-declared method.
619 mutable bool create_media_controller_called_ = false;
620 mutable cricket::MediaConfig create_media_controller_config_;
621 };
622
623 class PeerConnectionInterfaceTest : public testing::Test {
624 protected:
625 PeerConnectionInterfaceTest() {
626 #ifdef WEBRTC_ANDROID
627 webrtc::InitializeAndroidObjects();
628 #endif
629 }
630
631 virtual void SetUp() {
632 pc_factory_ = webrtc::CreatePeerConnectionFactory(
633 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
634 nullptr, nullptr, nullptr);
635 ASSERT_TRUE(pc_factory_);
636 pc_factory_for_test_ =
637 new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
638 pc_factory_for_test_->Initialize();
639 }
640
641 void CreatePeerConnection() {
642 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr);
643 }
644
645 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) {
646 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(),
647 constraints);
648 }
649
650 void CreatePeerConnectionWithIceTransportsType(
651 PeerConnectionInterface::IceTransportsType type) {
652 PeerConnectionInterface::RTCConfiguration config;
653 config.type = type;
654 return CreatePeerConnection(config, nullptr);
655 }
656
657 void CreatePeerConnectionWithIceServer(const std::string& uri,
658 const std::string& password) {
659 PeerConnectionInterface::RTCConfiguration config;
660 PeerConnectionInterface::IceServer server;
661 server.uri = uri;
662 server.password = password;
663 config.servers.push_back(server);
664 CreatePeerConnection(config, nullptr);
665 }
666
667 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config,
668 webrtc::MediaConstraintsInterface* constraints) {
669 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
670 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
671 port_allocator_ = port_allocator.get();
672
673 // DTLS does not work in a loopback call, so is disabled for most of the
674 // tests in this file. We only create a FakeIdentityService if the test
675 // explicitly sets the constraint.
676 FakeConstraints default_constraints;
677 if (!constraints) {
678 constraints = &default_constraints;
679
680 default_constraints.AddMandatory(
681 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
682 }
683
684 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
685 bool dtls;
686 if (FindConstraint(constraints,
687 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
688 &dtls,
689 nullptr) && dtls) {
690 cert_generator.reset(new FakeRTCCertificateGenerator());
691 }
692 pc_ = pc_factory_->CreatePeerConnection(
693 config, constraints, std::move(port_allocator),
694 std::move(cert_generator), &observer_);
695 ASSERT_TRUE(pc_.get() != NULL);
696 observer_.SetPeerConnectionInterface(pc_.get());
697 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
698 }
699
700 void CreatePeerConnectionExpectFail(const std::string& uri) {
701 PeerConnectionInterface::RTCConfiguration config;
702 PeerConnectionInterface::IceServer server;
703 server.uri = uri;
704 config.servers.push_back(server);
705
706 rtc::scoped_refptr<PeerConnectionInterface> pc;
707 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr,
708 &observer_);
709 EXPECT_EQ(nullptr, pc);
710 }
711
712 void CreatePeerConnectionWithDifferentConfigurations() {
713 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
714 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
715 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
716 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
717 EXPECT_EQ(kDefaultStunPort,
718 port_allocator_->stun_servers().begin()->port());
719
720 CreatePeerConnectionExpectFail(kStunInvalidPort);
721 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
722 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
723
724 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
725 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
726 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
727 EXPECT_EQ(kTurnUsername,
728 port_allocator_->turn_servers()[0].credentials.username);
729 EXPECT_EQ(kTurnPassword,
730 port_allocator_->turn_servers()[0].credentials.password);
731 EXPECT_EQ(kTurnHostname,
732 port_allocator_->turn_servers()[0].ports[0].address.hostname());
733 }
734
735 void ReleasePeerConnection() {
736 pc_ = NULL;
737 observer_.SetPeerConnectionInterface(NULL);
738 }
739
740 void AddVideoStream(const std::string& label) {
741 // Create a local stream.
742 rtc::scoped_refptr<MediaStreamInterface> stream(
743 pc_factory_->CreateLocalMediaStream(label));
744 rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
745 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
746 rtc::scoped_refptr<VideoTrackInterface> video_track(
747 pc_factory_->CreateVideoTrack(label + "v0", video_source));
748 stream->AddTrack(video_track.get());
749 EXPECT_TRUE(pc_->AddStream(stream));
750 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
751 observer_.renegotiation_needed_ = false;
752 }
753
754 void AddVoiceStream(const std::string& label) {
755 // Create a local stream.
756 rtc::scoped_refptr<MediaStreamInterface> stream(
757 pc_factory_->CreateLocalMediaStream(label));
758 rtc::scoped_refptr<AudioTrackInterface> audio_track(
759 pc_factory_->CreateAudioTrack(label + "a0", NULL));
760 stream->AddTrack(audio_track.get());
761 EXPECT_TRUE(pc_->AddStream(stream));
762 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
763 observer_.renegotiation_needed_ = false;
764 }
765
766 void AddAudioVideoStream(const std::string& stream_label,
767 const std::string& audio_track_label,
768 const std::string& video_track_label) {
769 // Create a local stream.
770 rtc::scoped_refptr<MediaStreamInterface> stream(
771 pc_factory_->CreateLocalMediaStream(stream_label));
772 rtc::scoped_refptr<AudioTrackInterface> audio_track(
773 pc_factory_->CreateAudioTrack(
774 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
775 stream->AddTrack(audio_track.get());
776 rtc::scoped_refptr<VideoTrackInterface> video_track(
777 pc_factory_->CreateVideoTrack(
778 video_track_label,
779 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
780 stream->AddTrack(video_track.get());
781 EXPECT_TRUE(pc_->AddStream(stream));
782 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
783 observer_.renegotiation_needed_ = false;
784 }
785
786 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
787 bool offer,
788 MediaConstraintsInterface* constraints) {
789 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
790 observer(new rtc::RefCountedObject<
791 MockCreateSessionDescriptionObserver>());
792 if (offer) {
793 pc_->CreateOffer(observer, constraints);
794 } else {
795 pc_->CreateAnswer(observer, constraints);
796 }
797 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
798 desc->reset(observer->release_desc());
799 return observer->result();
800 }
801
802 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
803 MediaConstraintsInterface* constraints) {
804 return DoCreateOfferAnswer(desc, true, constraints);
805 }
806
807 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
808 MediaConstraintsInterface* constraints) {
809 return DoCreateOfferAnswer(desc, false, constraints);
810 }
811
812 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) {
813 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
814 observer(new rtc::RefCountedObject<
815 MockSetSessionDescriptionObserver>());
816 if (local) {
817 pc_->SetLocalDescription(observer, desc);
818 } else {
819 pc_->SetRemoteDescription(observer, desc);
820 }
821 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
822 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
823 }
824 return observer->result();
825 }
826
827 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
828 return DoSetSessionDescription(desc, true);
829 }
830
831 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
832 return DoSetSessionDescription(desc, false);
833 }
834
835 // Calls PeerConnection::GetStats and check the return value.
836 // It does not verify the values in the StatReports since a RTCP packet might
837 // be required.
838 bool DoGetStats(MediaStreamTrackInterface* track) {
839 rtc::scoped_refptr<MockStatsObserver> observer(
840 new rtc::RefCountedObject<MockStatsObserver>());
841 if (!pc_->GetStats(
842 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard))
843 return false;
844 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
845 return observer->called();
846 }
847
848 void InitiateCall() {
849 CreatePeerConnection();
850 // Create a local stream with audio&video tracks.
851 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
852 CreateOfferReceiveAnswer();
853 }
854
855 // Verify that RTP Header extensions has been negotiated for audio and video.
856 void VerifyRemoteRtpHeaderExtensions() {
857 const cricket::MediaContentDescription* desc =
858 cricket::GetFirstAudioContentDescription(
859 pc_->remote_description()->description());
860 ASSERT_TRUE(desc != NULL);
861 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
862
863 desc = cricket::GetFirstVideoContentDescription(
864 pc_->remote_description()->description());
865 ASSERT_TRUE(desc != NULL);
866 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
867 }
868
869 void CreateOfferAsRemoteDescription() {
870 std::unique_ptr<SessionDescriptionInterface> offer;
871 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
872 std::string sdp;
873 EXPECT_TRUE(offer->ToString(&sdp));
874 SessionDescriptionInterface* remote_offer =
875 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
876 sdp, NULL);
877 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
878 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
879 }
880
881 void CreateAndSetRemoteOffer(const std::string& sdp) {
882 SessionDescriptionInterface* remote_offer =
883 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
884 sdp, nullptr);
885 EXPECT_TRUE(DoSetRemoteDescription(remote_offer));
886 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
887 }
888
889 void CreateAnswerAsLocalDescription() {
890 std::unique_ptr<SessionDescriptionInterface> answer;
891 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
892
893 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
894 // audio codec change, even if the parameter has nothing to do with
895 // receiving. Not all parameters are serialized to SDP.
896 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
897 // the SessionDescription, it is necessary to do that here to in order to
898 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
899 // https://code.google.com/p/webrtc/issues/detail?id=1356
900 std::string sdp;
901 EXPECT_TRUE(answer->ToString(&sdp));
902 SessionDescriptionInterface* new_answer =
903 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
904 sdp, NULL);
905 EXPECT_TRUE(DoSetLocalDescription(new_answer));
906 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
907 }
908
909 void CreatePrAnswerAsLocalDescription() {
910 std::unique_ptr<SessionDescriptionInterface> answer;
911 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
912
913 std::string sdp;
914 EXPECT_TRUE(answer->ToString(&sdp));
915 SessionDescriptionInterface* pr_answer =
916 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer,
917 sdp, NULL);
918 EXPECT_TRUE(DoSetLocalDescription(pr_answer));
919 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
920 }
921
922 void CreateOfferReceiveAnswer() {
923 CreateOfferAsLocalDescription();
924 std::string sdp;
925 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
926 CreateAnswerAsRemoteDescription(sdp);
927 }
928
929 void CreateOfferAsLocalDescription() {
930 std::unique_ptr<SessionDescriptionInterface> offer;
931 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
932 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
933 // audio codec change, even if the parameter has nothing to do with
934 // receiving. Not all parameters are serialized to SDP.
935 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
936 // the SessionDescription, it is necessary to do that here to in order to
937 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
938 // https://code.google.com/p/webrtc/issues/detail?id=1356
939 std::string sdp;
940 EXPECT_TRUE(offer->ToString(&sdp));
941 SessionDescriptionInterface* new_offer =
942 webrtc::CreateSessionDescription(
943 SessionDescriptionInterface::kOffer,
944 sdp, NULL);
945
946 EXPECT_TRUE(DoSetLocalDescription(new_offer));
947 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
948 // Wait for the ice_complete message, so that SDP will have candidates.
949 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
950 }
951
952 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
953 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
954 SessionDescriptionInterface::kAnswer);
955 EXPECT_TRUE(answer->Initialize(sdp, NULL));
956 EXPECT_TRUE(DoSetRemoteDescription(answer));
957 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
958 }
959
960 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
961 webrtc::JsepSessionDescription* pr_answer =
962 new webrtc::JsepSessionDescription(
963 SessionDescriptionInterface::kPrAnswer);
964 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL));
965 EXPECT_TRUE(DoSetRemoteDescription(pr_answer));
966 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
967 webrtc::JsepSessionDescription* answer =
968 new webrtc::JsepSessionDescription(
969 SessionDescriptionInterface::kAnswer);
970 EXPECT_TRUE(answer->Initialize(sdp, NULL));
971 EXPECT_TRUE(DoSetRemoteDescription(answer));
972 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
973 }
974
975 // Help function used for waiting until a the last signaled remote stream has
976 // the same label as |stream_label|. In a few of the tests in this file we
977 // answer with the same session description as we offer and thus we can
978 // check if OnAddStream have been called with the same stream as we offer to
979 // send.
980 void WaitAndVerifyOnAddStream(const std::string& stream_label) {
981 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout);
982 }
983
984 // Creates an offer and applies it as a local session description.
985 // Creates an answer with the same SDP an the offer but removes all lines
986 // that start with a:ssrc"
987 void CreateOfferReceiveAnswerWithoutSsrc() {
988 CreateOfferAsLocalDescription();
989 std::string sdp;
990 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
991 SetSsrcToZero(&sdp);
992 CreateAnswerAsRemoteDescription(sdp);
993 }
994
995 // This function creates a MediaStream with label kStreams[0] and
996 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
997 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
998 // is returned and the MediaStream is stored in
999 // |reference_collection_|
1000 std::unique_ptr<SessionDescriptionInterface>
1001 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1002 size_t number_of_video_tracks) {
1003 EXPECT_LE(number_of_audio_tracks, 2u);
1004 EXPECT_LE(number_of_video_tracks, 2u);
1005
1006 reference_collection_ = StreamCollection::Create();
1007 std::string sdp_ms1 = std::string(kSdpStringInit);
1008
1009 std::string mediastream_label = kStreams[0];
1010
1011 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1012 webrtc::MediaStream::Create(mediastream_label));
1013 reference_collection_->AddStream(stream);
1014
1015 if (number_of_audio_tracks > 0) {
1016 sdp_ms1 += std::string(kSdpStringAudio);
1017 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1018 AddAudioTrack(kAudioTracks[0], stream);
1019 }
1020 if (number_of_audio_tracks > 1) {
1021 sdp_ms1 += kSdpStringMs1Audio1;
1022 AddAudioTrack(kAudioTracks[1], stream);
1023 }
1024
1025 if (number_of_video_tracks > 0) {
1026 sdp_ms1 += std::string(kSdpStringVideo);
1027 sdp_ms1 += std::string(kSdpStringMs1Video0);
1028 AddVideoTrack(kVideoTracks[0], stream);
1029 }
1030 if (number_of_video_tracks > 1) {
1031 sdp_ms1 += kSdpStringMs1Video1;
1032 AddVideoTrack(kVideoTracks[1], stream);
1033 }
1034
1035 return std::unique_ptr<SessionDescriptionInterface>(
1036 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1037 sdp_ms1, nullptr));
1038 }
1039
1040 void AddAudioTrack(const std::string& track_id,
1041 MediaStreamInterface* stream) {
1042 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1043 webrtc::AudioTrack::Create(track_id, nullptr));
1044 ASSERT_TRUE(stream->AddTrack(audio_track));
1045 }
1046
1047 void AddVideoTrack(const std::string& track_id,
1048 MediaStreamInterface* stream) {
1049 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
1050 webrtc::VideoTrack::Create(track_id,
1051 webrtc::FakeVideoTrackSource::Create()));
1052 ASSERT_TRUE(stream->AddTrack(video_track));
1053 }
1054
1055 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1056 CreatePeerConnection();
1057 AddVoiceStream(kStreamLabel1);
1058 std::unique_ptr<SessionDescriptionInterface> offer;
1059 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1060 return offer;
1061 }
1062
1063 std::unique_ptr<SessionDescriptionInterface>
1064 CreateAnswerWithOneAudioStream() {
1065 std::unique_ptr<SessionDescriptionInterface> offer =
1066 CreateOfferWithOneAudioStream();
1067 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
1068 std::unique_ptr<SessionDescriptionInterface> answer;
1069 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1070 return answer;
1071 }
1072
1073 const std::string& GetFirstAudioStreamCname(
1074 const SessionDescriptionInterface* desc) {
1075 const cricket::ContentInfo* audio_content =
1076 cricket::GetFirstAudioContent(desc->description());
1077 const cricket::AudioContentDescription* audio_desc =
1078 static_cast<const cricket::AudioContentDescription*>(
1079 audio_content->description);
1080 return audio_desc->streams()[0].cname;
1081 }
1082
1083 cricket::FakePortAllocator* port_allocator_ = nullptr;
1084 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1085 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1086 rtc::scoped_refptr<PeerConnectionInterface> pc_;
1087 MockPeerConnectionObserver observer_;
1088 rtc::scoped_refptr<StreamCollection> reference_collection_;
1089 };
1090
1091 // Test that no callbacks on the PeerConnectionObserver are called after the
1092 // PeerConnection is closed.
1093 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) {
1094 rtc::scoped_refptr<PeerConnectionInterface> pc(
1095 pc_factory_for_test_->CreatePeerConnection(
1096 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr,
1097 nullptr, &observer_));
1098 observer_.SetPeerConnectionInterface(pc.get());
1099 pc->Close();
1100
1101 // No callbacks is expected to be called.
1102 observer_.callback_triggered_ = false;
1103 std::vector<cricket::Candidate> candidates;
1104 pc_factory_for_test_->transport_controller->SignalGatheringState(
1105 cricket::IceGatheringState{});
1106 pc_factory_for_test_->transport_controller->SignalCandidatesGathered(
1107 "", candidates);
1108 pc_factory_for_test_->transport_controller->SignalConnectionState(
1109 cricket::IceConnectionState{});
1110 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved(
1111 candidates);
1112 pc_factory_for_test_->transport_controller->SignalReceiving(false);
1113 EXPECT_FALSE(observer_.callback_triggered_);
1114 }
1115
1116 // Generate different CNAMEs when PeerConnections are created.
1117 // The CNAMEs are expected to be generated randomly. It is possible
1118 // that the test fails, though the possibility is very low.
1119 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
1120 std::unique_ptr<SessionDescriptionInterface> offer1 =
1121 CreateOfferWithOneAudioStream();
1122 std::unique_ptr<SessionDescriptionInterface> offer2 =
1123 CreateOfferWithOneAudioStream();
1124 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1125 GetFirstAudioStreamCname(offer2.get()));
1126 }
1127
1128 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
1129 std::unique_ptr<SessionDescriptionInterface> answer1 =
1130 CreateAnswerWithOneAudioStream();
1131 std::unique_ptr<SessionDescriptionInterface> answer2 =
1132 CreateAnswerWithOneAudioStream();
1133 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1134 GetFirstAudioStreamCname(answer2.get()));
1135 }
1136
1137 TEST_F(PeerConnectionInterfaceTest,
1138 CreatePeerConnectionWithDifferentConfigurations) {
1139 CreatePeerConnectionWithDifferentConfigurations();
1140 }
1141
1142 TEST_F(PeerConnectionInterfaceTest,
1143 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1144 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1145 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1146 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1147 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1148 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1149 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1150 port_allocator_->candidate_filter());
1151 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1152 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1153 }
1154
1155 // Test that when a PeerConnection is created with a nonzero candidate pool
1156 // size, the pooled PortAllocatorSession is created with all the attributes
1157 // in the RTCConfiguration.
1158 TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1159 PeerConnectionInterface::RTCConfiguration config;
1160 PeerConnectionInterface::IceServer server;
1161 server.uri = kStunAddressOnly;
1162 config.servers.push_back(server);
1163 config.type = PeerConnectionInterface::kRelay;
1164 config.disable_ipv6 = true;
1165 config.tcp_candidate_policy =
1166 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1167 config.candidate_network_policy =
1168 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1169 config.ice_candidate_pool_size = 1;
1170 CreatePeerConnection(config, nullptr);
1171
1172 const cricket::FakePortAllocatorSession* session =
1173 static_cast<const cricket::FakePortAllocatorSession*>(
1174 port_allocator_->GetPooledSession());
1175 ASSERT_NE(nullptr, session);
1176 EXPECT_EQ(1UL, session->stun_servers().size());
1177 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1178 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1179 EXPECT_LT(0U,
1180 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1181 }
1182
1183 // Test that the PeerConnection initializes the port allocator passed into it,
1184 // and on the correct thread.
1185 TEST_F(PeerConnectionInterfaceTest,
1186 CreatePeerConnectionInitializesPortAllocator) {
1187 rtc::Thread network_thread;
1188 network_thread.Start();
1189 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1190 webrtc::CreatePeerConnectionFactory(
1191 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
1192 nullptr, nullptr, nullptr));
1193 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1194 new cricket::FakePortAllocator(&network_thread, nullptr));
1195 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1196 PeerConnectionInterface::RTCConfiguration config;
1197 rtc::scoped_refptr<PeerConnectionInterface> pc(
1198 pc_factory->CreatePeerConnection(
1199 config, nullptr, std::move(port_allocator), nullptr, &observer_));
1200 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
1201 // so all we have to do here is check that it's initialized.
1202 EXPECT_TRUE(raw_port_allocator->initialized());
1203 }
1204
1205 // Check that GetConfiguration returns the configuration the PeerConnection was
1206 // constructed with, before SetConfiguration is called.
1207 TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1208 PeerConnectionInterface::RTCConfiguration config;
1209 config.type = PeerConnectionInterface::kRelay;
1210 CreatePeerConnection(config, nullptr);
1211
1212 PeerConnectionInterface::RTCConfiguration returned_config =
1213 pc_->GetConfiguration();
1214 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1215 }
1216
1217 // Check that GetConfiguration returns the last configuration passed into
1218 // SetConfiguration.
1219 TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1220 CreatePeerConnection();
1221
1222 PeerConnectionInterface::RTCConfiguration config;
1223 config.type = PeerConnectionInterface::kRelay;
1224 EXPECT_TRUE(pc_->SetConfiguration(config));
1225
1226 PeerConnectionInterface::RTCConfiguration returned_config =
1227 pc_->GetConfiguration();
1228 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1229 }
1230
1231 TEST_F(PeerConnectionInterfaceTest, AddStreams) {
1232 CreatePeerConnection();
1233 AddVideoStream(kStreamLabel1);
1234 AddVoiceStream(kStreamLabel2);
1235 ASSERT_EQ(2u, pc_->local_streams()->count());
1236
1237 // Test we can add multiple local streams to one peerconnection.
1238 rtc::scoped_refptr<MediaStreamInterface> stream(
1239 pc_factory_->CreateLocalMediaStream(kStreamLabel3));
1240 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1241 pc_factory_->CreateAudioTrack(kStreamLabel3,
1242 static_cast<AudioSourceInterface*>(NULL)));
1243 stream->AddTrack(audio_track.get());
1244 EXPECT_TRUE(pc_->AddStream(stream));
1245 EXPECT_EQ(3u, pc_->local_streams()->count());
1246
1247 // Remove the third stream.
1248 pc_->RemoveStream(pc_->local_streams()->at(2));
1249 EXPECT_EQ(2u, pc_->local_streams()->count());
1250
1251 // Remove the second stream.
1252 pc_->RemoveStream(pc_->local_streams()->at(1));
1253 EXPECT_EQ(1u, pc_->local_streams()->count());
1254
1255 // Remove the first stream.
1256 pc_->RemoveStream(pc_->local_streams()->at(0));
1257 EXPECT_EQ(0u, pc_->local_streams()->count());
1258 }
1259
1260 // Test that the created offer includes streams we added.
1261 TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) {
1262 CreatePeerConnection();
1263 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track");
1264 std::unique_ptr<SessionDescriptionInterface> offer;
1265 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1266
1267 const cricket::ContentInfo* audio_content =
1268 cricket::GetFirstAudioContent(offer->description());
1269 const cricket::AudioContentDescription* audio_desc =
1270 static_cast<const cricket::AudioContentDescription*>(
1271 audio_content->description);
1272 EXPECT_TRUE(
1273 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1274
1275 const cricket::ContentInfo* video_content =
1276 cricket::GetFirstVideoContent(offer->description());
1277 const cricket::VideoContentDescription* video_desc =
1278 static_cast<const cricket::VideoContentDescription*>(
1279 video_content->description);
1280 EXPECT_TRUE(
1281 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1282
1283 // Add another stream and ensure the offer includes both the old and new
1284 // streams.
1285 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2");
1286 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1287
1288 audio_content = cricket::GetFirstAudioContent(offer->description());
1289 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1290 audio_content->description);
1291 EXPECT_TRUE(
1292 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1293 EXPECT_TRUE(
1294 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2"));
1295
1296 video_content = cricket::GetFirstVideoContent(offer->description());
1297 video_desc = static_cast<const cricket::VideoContentDescription*>(
1298 video_content->description);
1299 EXPECT_TRUE(
1300 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1301 EXPECT_TRUE(
1302 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2"));
1303 }
1304
1305 TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
1306 CreatePeerConnection();
1307 AddVideoStream(kStreamLabel1);
1308 ASSERT_EQ(1u, pc_->local_streams()->count());
1309 pc_->RemoveStream(pc_->local_streams()->at(0));
1310 EXPECT_EQ(0u, pc_->local_streams()->count());
1311 }
1312
1313 // Test for AddTrack and RemoveTrack methods.
1314 // Tests that the created offer includes tracks we added,
1315 // and that the RtpSenders are created correctly.
1316 // Also tests that RemoveTrack removes the tracks from subsequent offers.
1317 TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
1318 CreatePeerConnection();
1319 // Create a dummy stream, so tracks share a stream label.
1320 rtc::scoped_refptr<MediaStreamInterface> stream(
1321 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1322 std::vector<MediaStreamInterface*> stream_list;
1323 stream_list.push_back(stream.get());
1324 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1325 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1326 rtc::scoped_refptr<VideoTrackInterface> video_track(
1327 pc_factory_->CreateVideoTrack(
1328 "video_track",
1329 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
1330 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1331 auto video_sender = pc_->AddTrack(video_track, stream_list);
1332 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1333 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]);
1334 EXPECT_EQ("audio_track", audio_sender->id());
1335 EXPECT_EQ(audio_track, audio_sender->track());
1336 EXPECT_EQ(1UL, video_sender->stream_ids().size());
1337 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]);
1338 EXPECT_EQ("video_track", video_sender->id());
1339 EXPECT_EQ(video_track, video_sender->track());
1340
1341 // Now create an offer and check for the senders.
1342 std::unique_ptr<SessionDescriptionInterface> offer;
1343 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1344
1345 const cricket::ContentInfo* audio_content =
1346 cricket::GetFirstAudioContent(offer->description());
1347 const cricket::AudioContentDescription* audio_desc =
1348 static_cast<const cricket::AudioContentDescription*>(
1349 audio_content->description);
1350 EXPECT_TRUE(
1351 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1352
1353 const cricket::ContentInfo* video_content =
1354 cricket::GetFirstVideoContent(offer->description());
1355 const cricket::VideoContentDescription* video_desc =
1356 static_cast<const cricket::VideoContentDescription*>(
1357 video_content->description);
1358 EXPECT_TRUE(
1359 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1360
1361 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1362
1363 // Now try removing the tracks.
1364 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1365 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1366
1367 // Create a new offer and ensure it doesn't contain the removed senders.
1368 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1369
1370 audio_content = cricket::GetFirstAudioContent(offer->description());
1371 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1372 audio_content->description);
1373 EXPECT_FALSE(
1374 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1375
1376 video_content = cricket::GetFirstVideoContent(offer->description());
1377 video_desc = static_cast<const cricket::VideoContentDescription*>(
1378 video_content->description);
1379 EXPECT_FALSE(
1380 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1381
1382 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1383
1384 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1385 // should return false.
1386 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1387 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1388 }
1389
1390 // Test creating senders without a stream specified,
1391 // expecting a random stream ID to be generated.
1392 TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
1393 CreatePeerConnection();
1394 // Create a dummy stream, so tracks share a stream label.
1395 rtc::scoped_refptr<AudioTrackInterface> audio_track(
1396 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1397 rtc::scoped_refptr<VideoTrackInterface> video_track(
1398 pc_factory_->CreateVideoTrack(
1399 "video_track",
1400 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
1401 auto audio_sender =
1402 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1403 auto video_sender =
1404 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1405 EXPECT_EQ("audio_track", audio_sender->id());
1406 EXPECT_EQ(audio_track, audio_sender->track());
1407 EXPECT_EQ("video_track", video_sender->id());
1408 EXPECT_EQ(video_track, video_sender->track());
1409 // If the ID is truly a random GUID, it should be infinitely unlikely they
1410 // will be the same.
1411 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1412 }
1413
1414 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1415 InitiateCall();
1416 WaitAndVerifyOnAddStream(kStreamLabel1);
1417 VerifyRemoteRtpHeaderExtensions();
1418 }
1419
1420 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
1421 CreatePeerConnection();
1422 AddVideoStream(kStreamLabel1);
1423 CreateOfferAsLocalDescription();
1424 std::string offer;
1425 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1426 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1427 WaitAndVerifyOnAddStream(kStreamLabel1);
1428 }
1429
1430 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
1431 CreatePeerConnection();
1432 AddVideoStream(kStreamLabel1);
1433
1434 CreateOfferAsRemoteDescription();
1435 CreateAnswerAsLocalDescription();
1436
1437 WaitAndVerifyOnAddStream(kStreamLabel1);
1438 }
1439
1440 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
1441 CreatePeerConnection();
1442 AddVideoStream(kStreamLabel1);
1443
1444 CreateOfferAsRemoteDescription();
1445 CreatePrAnswerAsLocalDescription();
1446 CreateAnswerAsLocalDescription();
1447
1448 WaitAndVerifyOnAddStream(kStreamLabel1);
1449 }
1450
1451 TEST_F(PeerConnectionInterfaceTest, Renegotiate) {
1452 InitiateCall();
1453 ASSERT_EQ(1u, pc_->remote_streams()->count());
1454 pc_->RemoveStream(pc_->local_streams()->at(0));
1455 CreateOfferReceiveAnswer();
1456 EXPECT_EQ(0u, pc_->remote_streams()->count());
1457 AddVideoStream(kStreamLabel1);
1458 CreateOfferReceiveAnswer();
1459 }
1460
1461 // Tests that after negotiating an audio only call, the respondent can perform a
1462 // renegotiation that removes the audio stream.
1463 TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) {
1464 CreatePeerConnection();
1465 AddVoiceStream(kStreamLabel1);
1466 CreateOfferAsRemoteDescription();
1467 CreateAnswerAsLocalDescription();
1468
1469 ASSERT_EQ(1u, pc_->remote_streams()->count());
1470 pc_->RemoveStream(pc_->local_streams()->at(0));
1471 CreateOfferReceiveAnswer();
1472 EXPECT_EQ(0u, pc_->remote_streams()->count());
1473 }
1474
1475 // Test that candidates are generated and that we can parse our own candidates.
1476 TEST_F(PeerConnectionInterfaceTest, IceCandidates) {
1477 CreatePeerConnection();
1478
1479 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1480 // SetRemoteDescription takes ownership of offer.
1481 std::unique_ptr<SessionDescriptionInterface> offer;
1482 AddVideoStream(kStreamLabel1);
1483 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1484 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
1485
1486 // SetLocalDescription takes ownership of answer.
1487 std::unique_ptr<SessionDescriptionInterface> answer;
1488 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1489 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
1490
1491 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout);
1492 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout);
1493
1494 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get()));
1495 }
1496
1497 // Test that CreateOffer and CreateAnswer will fail if the track labels are
1498 // not unique.
1499 TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) {
1500 CreatePeerConnection();
1501 // Create a regular offer for the CreateAnswer test later.
1502 std::unique_ptr<SessionDescriptionInterface> offer;
1503 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1504 EXPECT_TRUE(offer);
1505 offer.reset();
1506
1507 // Create a local stream with audio&video tracks having same label.
1508 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label");
1509
1510 // Test CreateOffer
1511 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
1512
1513 // Test CreateAnswer
1514 std::unique_ptr<SessionDescriptionInterface> answer;
1515 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
1516 }
1517
1518 // Test that we will get different SSRCs for each tracks in the offer and answer
1519 // we created.
1520 TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
1521 CreatePeerConnection();
1522 // Create a local stream with audio&video tracks having different labels.
1523 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1524
1525 // Test CreateOffer
1526 std::unique_ptr<SessionDescriptionInterface> offer;
1527 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1528 int audio_ssrc = 0;
1529 int video_ssrc = 0;
1530 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()),
1531 &audio_ssrc));
1532 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()),
1533 &video_ssrc));
1534 EXPECT_NE(audio_ssrc, video_ssrc);
1535
1536 // Test CreateAnswer
1537 EXPECT_TRUE(DoSetRemoteDescription(offer.release()));
1538 std::unique_ptr<SessionDescriptionInterface> answer;
1539 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
1540 audio_ssrc = 0;
1541 video_ssrc = 0;
1542 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()),
1543 &audio_ssrc));
1544 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()),
1545 &video_ssrc));
1546 EXPECT_NE(audio_ssrc, video_ssrc);
1547 }
1548
1549 // Test that it's possible to call AddTrack on a MediaStream after adding
1550 // the stream to a PeerConnection.
1551 // TODO(deadbeef): Remove this test once this behavior is no longer supported.
1552 TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
1553 CreatePeerConnection();
1554 // Create audio stream and add to PeerConnection.
1555 AddVoiceStream(kStreamLabel1);
1556 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1557
1558 // Add video track to the audio-only stream.
1559 rtc::scoped_refptr<VideoTrackInterface> video_track(
1560 pc_factory_->CreateVideoTrack(
1561 "video_label",
1562 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
1563 stream->AddTrack(video_track.get());
1564
1565 std::unique_ptr<SessionDescriptionInterface> offer;
1566 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1567
1568 const cricket::MediaContentDescription* video_desc =
1569 cricket::GetFirstVideoContentDescription(offer->description());
1570 EXPECT_TRUE(video_desc != nullptr);
1571 }
1572
1573 // Test that it's possible to call RemoveTrack on a MediaStream after adding
1574 // the stream to a PeerConnection.
1575 // TODO(deadbeef): Remove this test once this behavior is no longer supported.
1576 TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) {
1577 CreatePeerConnection();
1578 // Create audio/video stream and add to PeerConnection.
1579 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1580 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1581
1582 // Remove the video track.
1583 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1584
1585 std::unique_ptr<SessionDescriptionInterface> offer;
1586 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1587
1588 const cricket::MediaContentDescription* video_desc =
1589 cricket::GetFirstVideoContentDescription(offer->description());
1590 EXPECT_TRUE(video_desc == nullptr);
1591 }
1592
1593 // Test creating a sender with a stream ID, and ensure the ID is populated
1594 // in the offer.
1595 TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) {
1596 CreatePeerConnection();
1597 pc_->CreateSender("video", kStreamLabel1);
1598
1599 std::unique_ptr<SessionDescriptionInterface> offer;
1600 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1601
1602 const cricket::MediaContentDescription* video_desc =
1603 cricket::GetFirstVideoContentDescription(offer->description());
1604 ASSERT_TRUE(video_desc != nullptr);
1605 ASSERT_EQ(1u, video_desc->streams().size());
1606 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label);
1607 }
1608
1609 // Test that we can specify a certain track that we want statistics about.
1610 TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1611 InitiateCall();
1612 ASSERT_LT(0u, pc_->remote_streams()->count());
1613 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size());
1614 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
1615 pc_->remote_streams()->at(0)->GetAudioTracks()[0];
1616 EXPECT_TRUE(DoGetStats(remote_audio));
1617
1618 // Remove the stream. Since we are sending to our selves the local
1619 // and the remote stream is the same.
1620 pc_->RemoveStream(pc_->local_streams()->at(0));
1621 // Do a re-negotiation.
1622 CreateOfferReceiveAnswer();
1623
1624 ASSERT_EQ(0u, pc_->remote_streams()->count());
1625
1626 // Test that we still can get statistics for the old track. Even if it is not
1627 // sent any longer.
1628 EXPECT_TRUE(DoGetStats(remote_audio));
1629 }
1630
1631 // Test that we can get stats on a video track.
1632 TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1633 InitiateCall();
1634 ASSERT_LT(0u, pc_->remote_streams()->count());
1635 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size());
1636 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
1637 pc_->remote_streams()->at(0)->GetVideoTracks()[0];
1638 EXPECT_TRUE(DoGetStats(remote_video));
1639 }
1640
1641 // Test that we don't get statistics for an invalid track.
1642 TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
1643 InitiateCall();
1644 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
1645 pc_factory_->CreateAudioTrack("unknown track", NULL));
1646 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1647 }
1648
1649 // This test setup two RTP data channels in loop back.
1650 TEST_F(PeerConnectionInterfaceTest, TestDataChannel) {
1651 FakeConstraints constraints;
1652 constraints.SetAllowRtpDataChannels();
1653 CreatePeerConnection(&constraints);
1654 rtc::scoped_refptr<DataChannelInterface> data1 =
1655 pc_->CreateDataChannel("test1", NULL);
1656 rtc::scoped_refptr<DataChannelInterface> data2 =
1657 pc_->CreateDataChannel("test2", NULL);
1658 ASSERT_TRUE(data1 != NULL);
1659 std::unique_ptr<MockDataChannelObserver> observer1(
1660 new MockDataChannelObserver(data1));
1661 std::unique_ptr<MockDataChannelObserver> observer2(
1662 new MockDataChannelObserver(data2));
1663
1664 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1665 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1666 std::string data_to_send1 = "testing testing";
1667 std::string data_to_send2 = "testing something else";
1668 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1669
1670 CreateOfferReceiveAnswer();
1671 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1672 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1673
1674 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1675 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1676 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1677 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1678
1679 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1680 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1681
1682 data1->Close();
1683 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1684 CreateOfferReceiveAnswer();
1685 EXPECT_FALSE(observer1->IsOpen());
1686 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1687 EXPECT_TRUE(observer2->IsOpen());
1688
1689 data_to_send2 = "testing something else again";
1690 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1691
1692 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1693 }
1694
1695 // This test verifies that sendnig binary data over RTP data channels should
1696 // fail.
1697 TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
1698 FakeConstraints constraints;
1699 constraints.SetAllowRtpDataChannels();
1700 CreatePeerConnection(&constraints);
1701 rtc::scoped_refptr<DataChannelInterface> data1 =
1702 pc_->CreateDataChannel("test1", NULL);
1703 rtc::scoped_refptr<DataChannelInterface> data2 =
1704 pc_->CreateDataChannel("test2", NULL);
1705 ASSERT_TRUE(data1 != NULL);
1706 std::unique_ptr<MockDataChannelObserver> observer1(
1707 new MockDataChannelObserver(data1));
1708 std::unique_ptr<MockDataChannelObserver> observer2(
1709 new MockDataChannelObserver(data2));
1710
1711 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1712 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1713
1714 CreateOfferReceiveAnswer();
1715 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1716 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1717
1718 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1719 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1720
1721 rtc::CopyOnWriteBuffer buffer("test", 4);
1722 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1723 }
1724
1725 // This test setup a RTP data channels in loop back and test that a channel is
1726 // opened even if the remote end answer with a zero SSRC.
1727 TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
1728 FakeConstraints constraints;
1729 constraints.SetAllowRtpDataChannels();
1730 CreatePeerConnection(&constraints);
1731 rtc::scoped_refptr<DataChannelInterface> data1 =
1732 pc_->CreateDataChannel("test1", NULL);
1733 std::unique_ptr<MockDataChannelObserver> observer1(
1734 new MockDataChannelObserver(data1));
1735
1736 CreateOfferReceiveAnswerWithoutSsrc();
1737
1738 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1739
1740 data1->Close();
1741 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1742 CreateOfferReceiveAnswerWithoutSsrc();
1743 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1744 EXPECT_FALSE(observer1->IsOpen());
1745 }
1746
1747 // This test that if a data channel is added in an answer a receive only channel
1748 // channel is created.
1749 TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
1750 FakeConstraints constraints;
1751 constraints.SetAllowRtpDataChannels();
1752 CreatePeerConnection(&constraints);
1753
1754 std::string offer_label = "offer_channel";
1755 rtc::scoped_refptr<DataChannelInterface> offer_channel =
1756 pc_->CreateDataChannel(offer_label, NULL);
1757
1758 CreateOfferAsLocalDescription();
1759
1760 // Replace the data channel label in the offer and apply it as an answer.
1761 std::string receive_label = "answer_channel";
1762 std::string sdp;
1763 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1764 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
1765 receive_label.c_str(), receive_label.length(),
1766 &sdp);
1767 CreateAnswerAsRemoteDescription(sdp);
1768
1769 // Verify that a new incoming data channel has been created and that
1770 // it is open but can't we written to.
1771 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
1772 DataChannelInterface* received_channel = observer_.last_datachannel_;
1773 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
1774 EXPECT_EQ(receive_label, received_channel->label());
1775 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
1776
1777 // Verify that the channel we initially offered has been rejected.
1778 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1779
1780 // Do another offer / answer exchange and verify that the data channel is
1781 // opened.
1782 CreateOfferReceiveAnswer();
1783 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
1784 kTimeout);
1785 }
1786
1787 // This test that no data channel is returned if a reliable channel is
1788 // requested.
1789 // TODO(perkj): Remove this test once reliable channels are implemented.
1790 TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
1791 FakeConstraints constraints;
1792 constraints.SetAllowRtpDataChannels();
1793 CreatePeerConnection(&constraints);
1794
1795 std::string label = "test";
1796 webrtc::DataChannelInit config;
1797 config.reliable = true;
1798 rtc::scoped_refptr<DataChannelInterface> channel =
1799 pc_->CreateDataChannel(label, &config);
1800 EXPECT_TRUE(channel == NULL);
1801 }
1802
1803 // Verifies that duplicated label is not allowed for RTP data channel.
1804 TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
1805 FakeConstraints constraints;
1806 constraints.SetAllowRtpDataChannels();
1807 CreatePeerConnection(&constraints);
1808
1809 std::string label = "test";
1810 rtc::scoped_refptr<DataChannelInterface> channel =
1811 pc_->CreateDataChannel(label, nullptr);
1812 EXPECT_NE(channel, nullptr);
1813
1814 rtc::scoped_refptr<DataChannelInterface> dup_channel =
1815 pc_->CreateDataChannel(label, nullptr);
1816 EXPECT_EQ(dup_channel, nullptr);
1817 }
1818
1819 // This tests that a SCTP data channel is returned using different
1820 // DataChannelInit configurations.
1821 TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1822 FakeConstraints constraints;
1823 constraints.SetAllowDtlsSctpDataChannels();
1824 CreatePeerConnection(&constraints);
1825
1826 webrtc::DataChannelInit config;
1827
1828 rtc::scoped_refptr<DataChannelInterface> channel =
1829 pc_->CreateDataChannel("1", &config);
1830 EXPECT_TRUE(channel != NULL);
1831 EXPECT_TRUE(channel->reliable());
1832 EXPECT_TRUE(observer_.renegotiation_needed_);
1833 observer_.renegotiation_needed_ = false;
1834
1835 config.ordered = false;
1836 channel = pc_->CreateDataChannel("2", &config);
1837 EXPECT_TRUE(channel != NULL);
1838 EXPECT_TRUE(channel->reliable());
1839 EXPECT_FALSE(observer_.renegotiation_needed_);
1840
1841 config.ordered = true;
1842 config.maxRetransmits = 0;
1843 channel = pc_->CreateDataChannel("3", &config);
1844 EXPECT_TRUE(channel != NULL);
1845 EXPECT_FALSE(channel->reliable());
1846 EXPECT_FALSE(observer_.renegotiation_needed_);
1847
1848 config.maxRetransmits = -1;
1849 config.maxRetransmitTime = 0;
1850 channel = pc_->CreateDataChannel("4", &config);
1851 EXPECT_TRUE(channel != NULL);
1852 EXPECT_FALSE(channel->reliable());
1853 EXPECT_FALSE(observer_.renegotiation_needed_);
1854 }
1855
1856 // This tests that no data channel is returned if both maxRetransmits and
1857 // maxRetransmitTime are set for SCTP data channels.
1858 TEST_F(PeerConnectionInterfaceTest,
1859 CreateSctpDataChannelShouldFailForInvalidConfig) {
1860 FakeConstraints constraints;
1861 constraints.SetAllowDtlsSctpDataChannels();
1862 CreatePeerConnection(&constraints);
1863
1864 std::string label = "test";
1865 webrtc::DataChannelInit config;
1866 config.maxRetransmits = 0;
1867 config.maxRetransmitTime = 0;
1868
1869 rtc::scoped_refptr<DataChannelInterface> channel =
1870 pc_->CreateDataChannel(label, &config);
1871 EXPECT_TRUE(channel == NULL);
1872 }
1873
1874 // The test verifies that creating a SCTP data channel with an id already in use
1875 // or out of range should fail.
1876 TEST_F(PeerConnectionInterfaceTest,
1877 CreateSctpDataChannelWithInvalidIdShouldFail) {
1878 FakeConstraints constraints;
1879 constraints.SetAllowDtlsSctpDataChannels();
1880 CreatePeerConnection(&constraints);
1881
1882 webrtc::DataChannelInit config;
1883 rtc::scoped_refptr<DataChannelInterface> channel;
1884
1885 config.id = 1;
1886 channel = pc_->CreateDataChannel("1", &config);
1887 EXPECT_TRUE(channel != NULL);
1888 EXPECT_EQ(1, channel->id());
1889
1890 channel = pc_->CreateDataChannel("x", &config);
1891 EXPECT_TRUE(channel == NULL);
1892
1893 config.id = cricket::kMaxSctpSid;
1894 channel = pc_->CreateDataChannel("max", &config);
1895 EXPECT_TRUE(channel != NULL);
1896 EXPECT_EQ(config.id, channel->id());
1897
1898 config.id = cricket::kMaxSctpSid + 1;
1899 channel = pc_->CreateDataChannel("x", &config);
1900 EXPECT_TRUE(channel == NULL);
1901 }
1902
1903 // Verifies that duplicated label is allowed for SCTP data channel.
1904 TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
1905 FakeConstraints constraints;
1906 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1907 true);
1908 CreatePeerConnection(&constraints);
1909
1910 std::string label = "test";
1911 rtc::scoped_refptr<DataChannelInterface> channel =
1912 pc_->CreateDataChannel(label, nullptr);
1913 EXPECT_NE(channel, nullptr);
1914
1915 rtc::scoped_refptr<DataChannelInterface> dup_channel =
1916 pc_->CreateDataChannel(label, nullptr);
1917 EXPECT_NE(dup_channel, nullptr);
1918 }
1919
1920 // This test verifies that OnRenegotiationNeeded is fired for every new RTP
1921 // DataChannel.
1922 TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
1923 FakeConstraints constraints;
1924 constraints.SetAllowRtpDataChannels();
1925 CreatePeerConnection(&constraints);
1926
1927 rtc::scoped_refptr<DataChannelInterface> dc1 =
1928 pc_->CreateDataChannel("test1", NULL);
1929 EXPECT_TRUE(observer_.renegotiation_needed_);
1930 observer_.renegotiation_needed_ = false;
1931
1932 rtc::scoped_refptr<DataChannelInterface> dc2 =
1933 pc_->CreateDataChannel("test2", NULL);
1934 EXPECT_TRUE(observer_.renegotiation_needed_);
1935 }
1936
1937 // This test that a data channel closes when a PeerConnection is deleted/closed.
1938 TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
1939 FakeConstraints constraints;
1940 constraints.SetAllowRtpDataChannels();
1941 CreatePeerConnection(&constraints);
1942
1943 rtc::scoped_refptr<DataChannelInterface> data1 =
1944 pc_->CreateDataChannel("test1", NULL);
1945 rtc::scoped_refptr<DataChannelInterface> data2 =
1946 pc_->CreateDataChannel("test2", NULL);
1947 ASSERT_TRUE(data1 != NULL);
1948 std::unique_ptr<MockDataChannelObserver> observer1(
1949 new MockDataChannelObserver(data1));
1950 std::unique_ptr<MockDataChannelObserver> observer2(
1951 new MockDataChannelObserver(data2));
1952
1953 CreateOfferReceiveAnswer();
1954 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1955 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1956
1957 ReleasePeerConnection();
1958 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1959 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
1960 }
1961
1962 // This test that data channels can be rejected in an answer.
1963 TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) {
1964 FakeConstraints constraints;
1965 constraints.SetAllowRtpDataChannels();
1966 CreatePeerConnection(&constraints);
1967
1968 rtc::scoped_refptr<DataChannelInterface> offer_channel(
1969 pc_->CreateDataChannel("offer_channel", NULL));
1970
1971 CreateOfferAsLocalDescription();
1972
1973 // Create an answer where the m-line for data channels are rejected.
1974 std::string sdp;
1975 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1976 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription(
1977 SessionDescriptionInterface::kAnswer);
1978 EXPECT_TRUE(answer->Initialize(sdp, NULL));
1979 cricket::ContentInfo* data_info =
1980 answer->description()->GetContentByName("data");
1981 data_info->rejected = true;
1982
1983 DoSetRemoteDescription(answer);
1984 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
1985 }
1986
1987 // Test that we can create a session description from an SDP string from
1988 // FireFox, use it as a remote session description, generate an answer and use
1989 // the answer as a local description.
1990 TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
1991 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1992 FakeConstraints constraints;
1993 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1994 true);
1995 CreatePeerConnection(&constraints);
1996 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1997 SessionDescriptionInterface* desc =
1998 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
1999 webrtc::kFireFoxSdpOffer, nullptr);
2000 EXPECT_TRUE(DoSetSessionDescription(desc, false));
2001 CreateAnswerAsLocalDescription();
2002 ASSERT_TRUE(pc_->local_description() != NULL);
2003 ASSERT_TRUE(pc_->remote_description() != NULL);
2004
2005 const cricket::ContentInfo* content =
2006 cricket::GetFirstAudioContent(pc_->local_description()->description());
2007 ASSERT_TRUE(content != NULL);
2008 EXPECT_FALSE(content->rejected);
2009
2010 content =
2011 cricket::GetFirstVideoContent(pc_->local_description()->description());
2012 ASSERT_TRUE(content != NULL);
2013 EXPECT_FALSE(content->rejected);
2014 #ifdef HAVE_SCTP
2015 content =
2016 cricket::GetFirstDataContent(pc_->local_description()->description());
2017 ASSERT_TRUE(content != NULL);
2018 EXPECT_TRUE(content->rejected);
2019 #endif
2020 }
2021
2022 // Test that we can create an audio only offer and receive an answer with a
2023 // limited set of audio codecs and receive an updated offer with more audio
2024 // codecs, where the added codecs are not supported.
2025 TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
2026 CreatePeerConnection();
2027 AddVoiceStream("audio_label");
2028 CreateOfferAsLocalDescription();
2029
2030 SessionDescriptionInterface* answer =
2031 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2032 webrtc::kAudioSdp, nullptr);
2033 EXPECT_TRUE(DoSetSessionDescription(answer, false));
2034
2035 SessionDescriptionInterface* updated_offer =
2036 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2037 webrtc::kAudioSdpWithUnsupportedCodecs,
2038 nullptr);
2039 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false));
2040 CreateAnswerAsLocalDescription();
2041 }
2042
2043 // Test that if we're receiving (but not sending) a track, subsequent offers
2044 // will have m-lines with a=recvonly.
2045 TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2046 FakeConstraints constraints;
2047 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2048 true);
2049 CreatePeerConnection(&constraints);
2050 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2051 CreateAnswerAsLocalDescription();
2052
2053 // At this point we should be receiving stream 1, but not sending anything.
2054 // A new offer should be recvonly.
2055 std::unique_ptr<SessionDescriptionInterface> offer;
2056 DoCreateOffer(&offer, nullptr);
2057
2058 const cricket::ContentInfo* video_content =
2059 cricket::GetFirstVideoContent(offer->description());
2060 const cricket::VideoContentDescription* video_desc =
2061 static_cast<const cricket::VideoContentDescription*>(
2062 video_content->description);
2063 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction());
2064
2065 const cricket::ContentInfo* audio_content =
2066 cricket::GetFirstAudioContent(offer->description());
2067 const cricket::AudioContentDescription* audio_desc =
2068 static_cast<const cricket::AudioContentDescription*>(
2069 audio_content->description);
2070 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction());
2071 }
2072
2073 // Test that if we're receiving (but not sending) a track, and the
2074 // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2075 // false, the generated m-lines will be a=inactive.
2076 TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2077 FakeConstraints constraints;
2078 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2079 true);
2080 CreatePeerConnection(&constraints);
2081 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2082 CreateAnswerAsLocalDescription();
2083
2084 // At this point we should be receiving stream 1, but not sending anything.
2085 // A new offer would be recvonly, but we'll set the "no receive" constraints
2086 // to make it inactive.
2087 std::unique_ptr<SessionDescriptionInterface> offer;
2088 FakeConstraints offer_constraints;
2089 offer_constraints.AddMandatory(
2090 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false);
2091 offer_constraints.AddMandatory(
2092 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false);
2093 DoCreateOffer(&offer, &offer_constraints);
2094
2095 const cricket::ContentInfo* video_content =
2096 cricket::GetFirstVideoContent(offer->description());
2097 const cricket::VideoContentDescription* video_desc =
2098 static_cast<const cricket::VideoContentDescription*>(
2099 video_content->description);
2100 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction());
2101
2102 const cricket::ContentInfo* audio_content =
2103 cricket::GetFirstAudioContent(offer->description());
2104 const cricket::AudioContentDescription* audio_desc =
2105 static_cast<const cricket::AudioContentDescription*>(
2106 audio_content->description);
2107 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction());
2108 }
2109
2110 // Test that we can use SetConfiguration to change the ICE servers of the
2111 // PortAllocator.
2112 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2113 CreatePeerConnection();
2114
2115 PeerConnectionInterface::RTCConfiguration config;
2116 PeerConnectionInterface::IceServer server;
2117 server.uri = "stun:test_hostname";
2118 config.servers.push_back(server);
2119 EXPECT_TRUE(pc_->SetConfiguration(config));
2120
2121 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2122 EXPECT_EQ("test_hostname",
2123 port_allocator_->stun_servers().begin()->hostname());
2124 }
2125
2126 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2127 CreatePeerConnection();
2128 PeerConnectionInterface::RTCConfiguration config;
2129 config.type = PeerConnectionInterface::kRelay;
2130 EXPECT_TRUE(pc_->SetConfiguration(config));
2131 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2132 }
2133
2134 // Test that when SetConfiguration changes both the pool size and other
2135 // attributes, the pooled session is created with the updated attributes.
2136 TEST_F(PeerConnectionInterfaceTest,
2137 SetConfigurationCreatesPooledSessionCorrectly) {
2138 CreatePeerConnection();
2139 PeerConnectionInterface::RTCConfiguration config;
2140 config.ice_candidate_pool_size = 1;
2141 PeerConnectionInterface::IceServer server;
2142 server.uri = kStunAddressOnly;
2143 config.servers.push_back(server);
2144 config.type = PeerConnectionInterface::kRelay;
2145 EXPECT_TRUE(pc_->SetConfiguration(config));
2146
2147 const cricket::FakePortAllocatorSession* session =
2148 static_cast<const cricket::FakePortAllocatorSession*>(
2149 port_allocator_->GetPooledSession());
2150 ASSERT_NE(nullptr, session);
2151 EXPECT_EQ(1UL, session->stun_servers().size());
2152 }
2153
2154 // Test that PeerConnection::Close changes the states to closed and all remote
2155 // tracks change state to ended.
2156 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2157 // Initialize a PeerConnection and negotiate local and remote session
2158 // description.
2159 InitiateCall();
2160 ASSERT_EQ(1u, pc_->local_streams()->count());
2161 ASSERT_EQ(1u, pc_->remote_streams()->count());
2162
2163 pc_->Close();
2164
2165 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2166 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2167 pc_->ice_connection_state());
2168 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2169 pc_->ice_gathering_state());
2170
2171 EXPECT_EQ(1u, pc_->local_streams()->count());
2172 EXPECT_EQ(1u, pc_->remote_streams()->count());
2173
2174 rtc::scoped_refptr<MediaStreamInterface> remote_stream =
2175 pc_->remote_streams()->at(0);
2176 // Track state may be updated asynchronously.
2177 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2178 remote_stream->GetAudioTracks()[0]->state(), kTimeout);
2179 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2180 remote_stream->GetVideoTracks()[0]->state(), kTimeout);
2181 }
2182
2183 // Test that PeerConnection methods fails gracefully after
2184 // PeerConnection::Close has been called.
2185 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
2186 CreatePeerConnection();
2187 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
2188 CreateOfferAsRemoteDescription();
2189 CreateAnswerAsLocalDescription();
2190
2191 ASSERT_EQ(1u, pc_->local_streams()->count());
2192 rtc::scoped_refptr<MediaStreamInterface> local_stream =
2193 pc_->local_streams()->at(0);
2194
2195 pc_->Close();
2196
2197 pc_->RemoveStream(local_stream);
2198 EXPECT_FALSE(pc_->AddStream(local_stream));
2199
2200 ASSERT_FALSE(local_stream->GetAudioTracks().empty());
2201 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender(
2202 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0]));
2203 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed.
2204
2205 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2206
2207 EXPECT_TRUE(pc_->local_description() != NULL);
2208 EXPECT_TRUE(pc_->remote_description() != NULL);
2209
2210 std::unique_ptr<SessionDescriptionInterface> offer;
2211 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
2212 std::unique_ptr<SessionDescriptionInterface> answer;
2213 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
2214
2215 std::string sdp;
2216 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2217 SessionDescriptionInterface* remote_offer =
2218 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2219 sdp, NULL);
2220 EXPECT_FALSE(DoSetRemoteDescription(remote_offer));
2221
2222 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2223 SessionDescriptionInterface* local_offer =
2224 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer,
2225 sdp, NULL);
2226 EXPECT_FALSE(DoSetLocalDescription(local_offer));
2227 }
2228
2229 // Test that GetStats can still be called after PeerConnection::Close.
2230 TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) {
2231 InitiateCall();
2232 pc_->Close();
2233 DoGetStats(NULL);
2234 }
2235
2236 // NOTE: The series of tests below come from what used to be
2237 // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2238 // setting a remote or local description has the expected effects.
2239
2240 // This test verifies that the remote MediaStreams corresponding to a received
2241 // SDP string is created. In this test the two separate MediaStreams are
2242 // signaled.
2243 TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2244 FakeConstraints constraints;
2245 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2246 true);
2247 CreatePeerConnection(&constraints);
2248 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2249
2250 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
2251 EXPECT_TRUE(
2252 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2253 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2254 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2255
2256 // Create a session description based on another SDP with another
2257 // MediaStream.
2258 CreateAndSetRemoteOffer(kSdpStringWithStream1And2);
2259
2260 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
2261 EXPECT_TRUE(
2262 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2263 }
2264
2265 // This test verifies that when remote tracks are added/removed from SDP, the
2266 // created remote streams are updated appropriately.
2267 TEST_F(PeerConnectionInterfaceTest,
2268 AddRemoveTrackFromExistingRemoteMediaStream) {
2269 FakeConstraints constraints;
2270 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2271 true);
2272 CreatePeerConnection(&constraints);
2273 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
2274 CreateSessionDescriptionAndReference(1, 1);
2275 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
2276 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2277 reference_collection_));
2278
2279 // Add extra audio and video tracks to the same MediaStream.
2280 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
2281 CreateSessionDescriptionAndReference(2, 2);
2282 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
2283 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2284 reference_collection_));
2285 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
2286 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2287 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
2288 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
2289 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2290 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
2291
2292 // Remove the extra audio and video tracks.
2293 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
2294 CreateSessionDescriptionAndReference(1, 1);
2295 MockTrackObserver audio_track_observer(audio_track2);
2296 MockTrackObserver video_track_observer(video_track2);
2297
2298 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2299 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
2300 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
2301 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2302 reference_collection_));
2303 // Track state may be updated asynchronously.
2304 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2305 audio_track2->state(), kTimeout);
2306 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2307 video_track2->state(), kTimeout);
2308 }
2309
2310 // This tests that remote tracks are ended if a local session description is set
2311 // that rejects the media content type.
2312 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
2313 FakeConstraints constraints;
2314 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2315 true);
2316 CreatePeerConnection(&constraints);
2317 // First create and set a remote offer, then reject its video content in our
2318 // answer.
2319 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2320 ASSERT_EQ(1u, observer_.remote_streams()->count());
2321 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2322 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2323 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2324
2325 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video =
2326 remote_stream->GetVideoTracks()[0];
2327 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state());
2328 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio =
2329 remote_stream->GetAudioTracks()[0];
2330 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2331
2332 std::unique_ptr<SessionDescriptionInterface> local_answer;
2333 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
2334 cricket::ContentInfo* video_info =
2335 local_answer->description()->GetContentByName("video");
2336 video_info->rejected = true;
2337 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2338 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2339 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2340
2341 // Now create an offer where we reject both video and audio.
2342 std::unique_ptr<SessionDescriptionInterface> local_offer;
2343 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
2344 video_info = local_offer->description()->GetContentByName("video");
2345 ASSERT_TRUE(video_info != nullptr);
2346 video_info->rejected = true;
2347 cricket::ContentInfo* audio_info =
2348 local_offer->description()->GetContentByName("audio");
2349 ASSERT_TRUE(audio_info != nullptr);
2350 audio_info->rejected = true;
2351 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
2352 // Track state may be updated asynchronously.
2353 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2354 remote_audio->state(), kTimeout);
2355 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2356 remote_video->state(), kTimeout);
2357 }
2358
2359 // This tests that we won't crash if the remote track has been removed outside
2360 // of PeerConnection and then PeerConnection tries to reject the track.
2361 TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2362 FakeConstraints constraints;
2363 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2364 true);
2365 CreatePeerConnection(&constraints);
2366 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2367 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2368 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2369 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2370
2371 std::unique_ptr<SessionDescriptionInterface> local_answer(
2372 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer,
2373 kSdpStringWithStream1, nullptr));
2374 cricket::ContentInfo* video_info =
2375 local_answer->description()->GetContentByName("video");
2376 video_info->rejected = true;
2377 cricket::ContentInfo* audio_info =
2378 local_answer->description()->GetContentByName("audio");
2379 audio_info->rejected = true;
2380 EXPECT_TRUE(DoSetLocalDescription(local_answer.release()));
2381
2382 // No crash is a pass.
2383 }
2384
2385 // This tests that if a recvonly remote description is set, no remote streams
2386 // will be created, even if the description contains SSRCs/MSIDs.
2387 // See: https://code.google.com/p/webrtc/issues/detail?id=5054
2388 TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2389 FakeConstraints constraints;
2390 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2391 true);
2392 CreatePeerConnection(&constraints);
2393
2394 std::string recvonly_offer = kSdpStringWithStream1;
2395 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2396 strlen(kRecvonly), &recvonly_offer);
2397 CreateAndSetRemoteOffer(recvonly_offer);
2398
2399 EXPECT_EQ(0u, observer_.remote_streams()->count());
2400 }
2401
2402 // This tests that a default MediaStream is created if a remote session
2403 // description doesn't contain any streams and no MSID support.
2404 // It also tests that the default stream is updated if a video m-line is added
2405 // in a subsequent session description.
2406 TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) {
2407 FakeConstraints constraints;
2408 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2409 true);
2410 CreatePeerConnection(&constraints);
2411 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2412
2413 ASSERT_EQ(1u, observer_.remote_streams()->count());
2414 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2415
2416 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2417 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2418 EXPECT_EQ("default", remote_stream->label());
2419
2420 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2421 ASSERT_EQ(1u, observer_.remote_streams()->count());
2422 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2423 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
2424 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2425 remote_stream->GetAudioTracks()[0]->state());
2426 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2427 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
2428 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2429 remote_stream->GetVideoTracks()[0]->state());
2430 }
2431
2432 // This tests that a default MediaStream is created if a remote session
2433 // description doesn't contain any streams and media direction is send only.
2434 TEST_F(PeerConnectionInterfaceTest,
2435 SendOnlySdpWithoutMsidCreatesDefaultStream) {
2436 FakeConstraints constraints;
2437 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2438 true);
2439 CreatePeerConnection(&constraints);
2440 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2441
2442 ASSERT_EQ(1u, observer_.remote_streams()->count());
2443 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2444
2445 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2446 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2447 EXPECT_EQ("default", remote_stream->label());
2448 }
2449
2450 // This tests that it won't crash when PeerConnection tries to remove
2451 // a remote track that as already been removed from the MediaStream.
2452 TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) {
2453 FakeConstraints constraints;
2454 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2455 true);
2456 CreatePeerConnection(&constraints);
2457 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2458 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2459 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2460 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2461
2462 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2463
2464 // No crash is a pass.
2465 }
2466
2467 // This tests that a default MediaStream is created if the remote session
2468 // description doesn't contain any streams and don't contain an indication if
2469 // MSID is supported.
2470 TEST_F(PeerConnectionInterfaceTest,
2471 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
2472 FakeConstraints constraints;
2473 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2474 true);
2475 CreatePeerConnection(&constraints);
2476 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2477
2478 ASSERT_EQ(1u, observer_.remote_streams()->count());
2479 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2480 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2481 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2482 }
2483
2484 // This tests that a default MediaStream is not created if the remote session
2485 // description doesn't contain any streams but does support MSID.
2486 TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) {
2487 FakeConstraints constraints;
2488 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2489 true);
2490 CreatePeerConnection(&constraints);
2491 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2492 EXPECT_EQ(0u, observer_.remote_streams()->count());
2493 }
2494
2495 // This tests that when setting a new description, the old default tracks are
2496 // not destroyed and recreated.
2497 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
2498 TEST_F(PeerConnectionInterfaceTest,
2499 DefaultTracksNotDestroyedAndRecreated) {
2500 FakeConstraints constraints;
2501 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2502 true);
2503 CreatePeerConnection(&constraints);
2504 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2505
2506 ASSERT_EQ(1u, observer_.remote_streams()->count());
2507 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2508 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2509
2510 // Set the track to "disabled", then set a new description and ensure the
2511 // track is still disabled, which ensures it hasn't been recreated.
2512 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2513 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2514 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2515 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2516 }
2517
2518 // This tests that a default MediaStream is not created if a remote session
2519 // description is updated to not have any MediaStreams.
2520 TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) {
2521 FakeConstraints constraints;
2522 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2523 true);
2524 CreatePeerConnection(&constraints);
2525 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2526 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
2527 EXPECT_TRUE(
2528 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2529
2530 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2531 EXPECT_EQ(0u, observer_.remote_streams()->count());
2532 }
2533
2534 // This tests that an RtpSender is created when the local description is set
2535 // after adding a local stream.
2536 // TODO(deadbeef): This test and the one below it need to be updated when
2537 // an RtpSender's lifetime isn't determined by when a local description is set.
2538 TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) {
2539 FakeConstraints constraints;
2540 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2541 true);
2542 CreatePeerConnection(&constraints);
2543
2544 // Create an offer with 1 stream with 2 tracks of each type.
2545 rtc::scoped_refptr<StreamCollection> stream_collection =
2546 CreateStreamCollection(1, 2);
2547 pc_->AddStream(stream_collection->at(0));
2548 std::unique_ptr<SessionDescriptionInterface> offer;
2549 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2550 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2551
2552 auto senders = pc_->GetSenders();
2553 EXPECT_EQ(4u, senders.size());
2554 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2555 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2556 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2557 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2558
2559 // Remove an audio and video track.
2560 pc_->RemoveStream(stream_collection->at(0));
2561 stream_collection = CreateStreamCollection(1, 1);
2562 pc_->AddStream(stream_collection->at(0));
2563 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2564 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2565
2566 senders = pc_->GetSenders();
2567 EXPECT_EQ(2u, senders.size());
2568 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2569 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2570 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2571 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2572 }
2573
2574 // This tests that an RtpSender is created when the local description is set
2575 // before adding a local stream.
2576 TEST_F(PeerConnectionInterfaceTest,
2577 AddLocalStreamAfterLocalDescriptionChanged) {
2578 FakeConstraints constraints;
2579 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2580 true);
2581 CreatePeerConnection(&constraints);
2582
2583 rtc::scoped_refptr<StreamCollection> stream_collection =
2584 CreateStreamCollection(1, 2);
2585 // Add a stream to create the offer, but remove it afterwards.
2586 pc_->AddStream(stream_collection->at(0));
2587 std::unique_ptr<SessionDescriptionInterface> offer;
2588 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2589 pc_->RemoveStream(stream_collection->at(0));
2590
2591 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2592 auto senders = pc_->GetSenders();
2593 EXPECT_EQ(0u, senders.size());
2594
2595 pc_->AddStream(stream_collection->at(0));
2596 senders = pc_->GetSenders();
2597 EXPECT_EQ(4u, senders.size());
2598 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2599 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2600 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2601 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2602 }
2603
2604 // This tests that the expected behavior occurs if the SSRC on a local track is
2605 // changed when SetLocalDescription is called.
2606 TEST_F(PeerConnectionInterfaceTest,
2607 ChangeSsrcOnTrackInLocalSessionDescription) {
2608 FakeConstraints constraints;
2609 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2610 true);
2611 CreatePeerConnection(&constraints);
2612
2613 rtc::scoped_refptr<StreamCollection> stream_collection =
2614 CreateStreamCollection(2, 1);
2615 pc_->AddStream(stream_collection->at(0));
2616 std::unique_ptr<SessionDescriptionInterface> offer;
2617 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2618 // Grab a copy of the offer before it gets passed into the PC.
2619 std::unique_ptr<JsepSessionDescription> modified_offer(
2620 new JsepSessionDescription(JsepSessionDescription::kOffer));
2621 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
2622 offer->session_version());
2623 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2624
2625 auto senders = pc_->GetSenders();
2626 EXPECT_EQ(2u, senders.size());
2627 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2628 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2629
2630 // Change the ssrc of the audio and video track.
2631 cricket::MediaContentDescription* desc =
2632 cricket::GetFirstAudioContentDescription(modified_offer->description());
2633 ASSERT_TRUE(desc != NULL);
2634 for (StreamParams& stream : desc->mutable_streams()) {
2635 for (unsigned int& ssrc : stream.ssrcs) {
2636 ++ssrc;
2637 }
2638 }
2639
2640 desc =
2641 cricket::GetFirstVideoContentDescription(modified_offer->description());
2642 ASSERT_TRUE(desc != NULL);
2643 for (StreamParams& stream : desc->mutable_streams()) {
2644 for (unsigned int& ssrc : stream.ssrcs) {
2645 ++ssrc;
2646 }
2647 }
2648
2649 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release()));
2650 senders = pc_->GetSenders();
2651 EXPECT_EQ(2u, senders.size());
2652 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2653 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2654 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2655 // changed.
2656 }
2657
2658 // This tests that the expected behavior occurs if a new session description is
2659 // set with the same tracks, but on a different MediaStream.
2660 TEST_F(PeerConnectionInterfaceTest,
2661 SignalSameTracksInSeparateMediaStream) {
2662 FakeConstraints constraints;
2663 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2664 true);
2665 CreatePeerConnection(&constraints);
2666
2667 rtc::scoped_refptr<StreamCollection> stream_collection =
2668 CreateStreamCollection(2, 1);
2669 pc_->AddStream(stream_collection->at(0));
2670 std::unique_ptr<SessionDescriptionInterface> offer;
2671 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2672 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2673
2674 auto senders = pc_->GetSenders();
2675 EXPECT_EQ(2u, senders.size());
2676 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2677 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
2678
2679 // Add a new MediaStream but with the same tracks as in the first stream.
2680 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2681 webrtc::MediaStream::Create(kStreams[1]));
2682 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2683 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
2684 pc_->AddStream(stream_1);
2685
2686 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2687 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
2688
2689 auto new_senders = pc_->GetSenders();
2690 // Should be the same senders as before, but with updated stream id.
2691 // Note that this behavior is subject to change in the future.
2692 // We may decide the PC should ignore existing tracks in AddStream.
2693 EXPECT_EQ(senders, new_senders);
2694 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2695 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
2696 }
2697
2698 // This tests that PeerConnectionObserver::OnAddTrack is correctly called.
2699 TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) {
2700 FakeConstraints constraints;
2701 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2702 true);
2703 CreatePeerConnection(&constraints);
2704 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2705 EXPECT_EQ(observer_.num_added_tracks_, 1);
2706 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2707
2708 // Create and set the updated remote SDP.
2709 CreateAndSetRemoteOffer(kSdpStringWithStream1);
2710 EXPECT_EQ(observer_.num_added_tracks_, 2);
2711 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2712 }
2713
2714 class PeerConnectionMediaConfigTest : public testing::Test {
2715 protected:
2716 void SetUp() override {
2717 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
2718 pcf_->Initialize();
2719 }
2720 const cricket::MediaConfig& TestCreatePeerConnection(
2721 const PeerConnectionInterface::RTCConfiguration& config,
2722 const MediaConstraintsInterface *constraints) {
2723 pcf_->create_media_controller_called_ = false;
2724
2725 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection(
2726 config, constraints, nullptr, nullptr, &observer_));
2727 EXPECT_TRUE(pc.get());
2728 EXPECT_TRUE(pcf_->create_media_controller_called_);
2729 return pcf_->create_media_controller_config_;
2730 }
2731
2732 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
2733 MockPeerConnectionObserver observer_;
2734 };
2735
2736 // This test verifies the default behaviour with no constraints and a
2737 // default RTCConfiguration.
2738 TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
2739 PeerConnectionInterface::RTCConfiguration config;
2740 FakeConstraints constraints;
2741
2742 const cricket::MediaConfig& media_config =
2743 TestCreatePeerConnection(config, &constraints);
2744
2745 EXPECT_FALSE(media_config.enable_dscp);
2746 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection);
2747 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing);
2748 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
2749 }
2750
2751 // This test verifies the DSCP constraint is recognized and passed to
2752 // the CreateMediaController call.
2753 TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) {
2754 PeerConnectionInterface::RTCConfiguration config;
2755 FakeConstraints constraints;
2756
2757 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true);
2758 const cricket::MediaConfig& media_config =
2759 TestCreatePeerConnection(config, &constraints);
2760
2761 EXPECT_TRUE(media_config.enable_dscp);
2762 }
2763
2764 // This test verifies the cpu overuse detection constraint is
2765 // recognized and passed to the CreateMediaController call.
2766 TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) {
2767 PeerConnectionInterface::RTCConfiguration config;
2768 FakeConstraints constraints;
2769
2770 constraints.AddOptional(
2771 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false);
2772 const cricket::MediaConfig media_config =
2773 TestCreatePeerConnection(config, &constraints);
2774
2775 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection);
2776 }
2777
2778 // This test verifies that the disable_prerenderer_smoothing flag is
2779 // propagated from RTCConfiguration to the CreateMediaController call.
2780 TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
2781 PeerConnectionInterface::RTCConfiguration config;
2782 FakeConstraints constraints;
2783
2784 config.set_prerenderer_smoothing(false);
2785 const cricket::MediaConfig& media_config =
2786 TestCreatePeerConnection(config, &constraints);
2787
2788 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing);
2789 }
2790
2791 // This test verifies the suspend below min bitrate constraint is
2792 // recognized and passed to the CreateMediaController call.
2793 TEST_F(PeerConnectionMediaConfigTest,
2794 TestSuspendBelowMinBitrateConstraintTrue) {
2795 PeerConnectionInterface::RTCConfiguration config;
2796 FakeConstraints constraints;
2797
2798 constraints.AddOptional(
2799 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
2800 true);
2801 const cricket::MediaConfig media_config =
2802 TestCreatePeerConnection(config, &constraints);
2803
2804 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate);
2805 }
2806
2807 // The following tests verify that session options are created correctly.
2808 // TODO(deadbeef): Convert these tests to be more end-to-end. Instead of
2809 // "verify options are converted correctly", should be "pass options into
2810 // CreateOffer and verify the correct offer is produced."
2811
2812 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) {
2813 RTCOfferAnswerOptions rtc_options;
2814 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
2815
2816 cricket::MediaSessionOptions options;
2817 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
2818
2819 rtc_options.offer_to_receive_audio =
2820 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
2821 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
2822 }
2823
2824 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) {
2825 RTCOfferAnswerOptions rtc_options;
2826 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
2827
2828 cricket::MediaSessionOptions options;
2829 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
2830
2831 rtc_options.offer_to_receive_video =
2832 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
2833 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options));
2834 }
2835
2836 // Test that a MediaSessionOptions is created for an offer if
2837 // OfferToReceiveAudio and OfferToReceiveVideo options are set.
2838 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) {
2839 RTCOfferAnswerOptions rtc_options;
2840 rtc_options.offer_to_receive_audio = 1;
2841 rtc_options.offer_to_receive_video = 1;
2842
2843 cricket::MediaSessionOptions options;
2844 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2845 EXPECT_TRUE(options.has_audio());
2846 EXPECT_TRUE(options.has_video());
2847 EXPECT_TRUE(options.bundle_enabled);
2848 }
2849
2850 // Test that a correct MediaSessionOptions is created for an offer if
2851 // OfferToReceiveAudio is set.
2852 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) {
2853 RTCOfferAnswerOptions rtc_options;
2854 rtc_options.offer_to_receive_audio = 1;
2855
2856 cricket::MediaSessionOptions options;
2857 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2858 EXPECT_TRUE(options.has_audio());
2859 EXPECT_FALSE(options.has_video());
2860 EXPECT_TRUE(options.bundle_enabled);
2861 }
2862
2863 // Test that a correct MediaSessionOptions is created for an offer if
2864 // the default OfferOptions are used.
2865 TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) {
2866 RTCOfferAnswerOptions rtc_options;
2867
2868 cricket::MediaSessionOptions options;
2869 options.transport_options["audio"] = cricket::TransportOptions();
2870 options.transport_options["video"] = cricket::TransportOptions();
2871 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2872 EXPECT_TRUE(options.has_audio());
2873 EXPECT_FALSE(options.has_video());
2874 EXPECT_TRUE(options.bundle_enabled);
2875 EXPECT_TRUE(options.vad_enabled);
2876 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
2877 EXPECT_FALSE(options.transport_options["video"].ice_restart);
2878 }
2879
2880 // Test that a correct MediaSessionOptions is created for an offer if
2881 // OfferToReceiveVideo is set.
2882 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) {
2883 RTCOfferAnswerOptions rtc_options;
2884 rtc_options.offer_to_receive_audio = 0;
2885 rtc_options.offer_to_receive_video = 1;
2886
2887 cricket::MediaSessionOptions options;
2888 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2889 EXPECT_FALSE(options.has_audio());
2890 EXPECT_TRUE(options.has_video());
2891 EXPECT_TRUE(options.bundle_enabled);
2892 }
2893
2894 // Test that a correct MediaSessionOptions is created for an offer if
2895 // UseRtpMux is set to false.
2896 TEST(CreateSessionOptionsTest,
2897 GetMediaSessionOptionsForOfferWithBundleDisabled) {
2898 RTCOfferAnswerOptions rtc_options;
2899 rtc_options.offer_to_receive_audio = 1;
2900 rtc_options.offer_to_receive_video = 1;
2901 rtc_options.use_rtp_mux = false;
2902
2903 cricket::MediaSessionOptions options;
2904 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2905 EXPECT_TRUE(options.has_audio());
2906 EXPECT_TRUE(options.has_video());
2907 EXPECT_FALSE(options.bundle_enabled);
2908 }
2909
2910 // Test that a correct MediaSessionOptions is created to restart ice if
2911 // IceRestart is set. It also tests that subsequent MediaSessionOptions don't
2912 // have |audio_transport_options.ice_restart| etc. set.
2913 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) {
2914 RTCOfferAnswerOptions rtc_options;
2915 rtc_options.ice_restart = true;
2916
2917 cricket::MediaSessionOptions options;
2918 options.transport_options["audio"] = cricket::TransportOptions();
2919 options.transport_options["video"] = cricket::TransportOptions();
2920 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2921 EXPECT_TRUE(options.transport_options["audio"].ice_restart);
2922 EXPECT_TRUE(options.transport_options["video"].ice_restart);
2923
2924 rtc_options = RTCOfferAnswerOptions();
2925 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options));
2926 EXPECT_FALSE(options.transport_options["audio"].ice_restart);
2927 EXPECT_FALSE(options.transport_options["video"].ice_restart);
2928 }
2929
2930 // Test that the MediaConstraints in an answer don't affect if audio and video
2931 // is offered in an offer but that if kOfferToReceiveAudio or
2932 // kOfferToReceiveVideo constraints are true in an offer, the media type will be
2933 // included in subsequent answers.
2934 TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) {
2935 FakeConstraints answer_c;
2936 answer_c.SetMandatoryReceiveAudio(true);
2937 answer_c.SetMandatoryReceiveVideo(true);
2938
2939 cricket::MediaSessionOptions answer_options;
2940 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options));
2941 EXPECT_TRUE(answer_options.has_audio());
2942 EXPECT_TRUE(answer_options.has_video());
2943
2944 RTCOfferAnswerOptions rtc_offer_options;
2945
2946 cricket::MediaSessionOptions offer_options;
2947 EXPECT_TRUE(
2948 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options));
2949 EXPECT_TRUE(offer_options.has_audio());
2950 EXPECT_TRUE(offer_options.has_video());
2951
2952 RTCOfferAnswerOptions updated_rtc_offer_options;
2953 updated_rtc_offer_options.offer_to_receive_audio = 1;
2954 updated_rtc_offer_options.offer_to_receive_video = 1;
2955
2956 cricket::MediaSessionOptions updated_offer_options;
2957 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false,
2958 &updated_offer_options));
2959 EXPECT_TRUE(updated_offer_options.has_audio());
2960 EXPECT_TRUE(updated_offer_options.has_video());
2961
2962 // Since an offer has been created with both audio and video, subsequent
2963 // offers and answers should contain both audio and video.
2964 // Answers will only contain the media types that exist in the offer
2965 // regardless of the value of |updated_answer_options.has_audio| and
2966 // |updated_answer_options.has_video|.
2967 FakeConstraints updated_answer_c;
2968 answer_c.SetMandatoryReceiveAudio(false);
2969 answer_c.SetMandatoryReceiveVideo(false);
2970
2971 cricket::MediaSessionOptions updated_answer_options;
2972 EXPECT_TRUE(
2973 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2974 EXPECT_TRUE(updated_answer_options.has_audio());
2975 EXPECT_TRUE(updated_answer_options.has_video());
2976 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698