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

Side by Side Diff: talk/app/webrtc/peerconnectioninterface_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698