OLD | NEW |
| (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 <stdio.h> | |
29 | |
30 #include <algorithm> | |
31 #include <list> | |
32 #include <map> | |
33 #include <utility> | |
34 #include <vector> | |
35 | |
36 #include "talk/app/webrtc/dtmfsender.h" | |
37 #include "talk/app/webrtc/fakemetricsobserver.h" | |
38 #include "talk/app/webrtc/localaudiosource.h" | |
39 #include "talk/app/webrtc/mediastreaminterface.h" | |
40 #include "talk/app/webrtc/peerconnection.h" | |
41 #include "talk/app/webrtc/peerconnectionfactory.h" | |
42 #include "talk/app/webrtc/peerconnectioninterface.h" | |
43 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" | |
44 #include "talk/app/webrtc/test/fakeconstraints.h" | |
45 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | |
46 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" | |
47 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" | |
48 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" | |
49 #include "talk/app/webrtc/videosourceinterface.h" | |
50 #include "talk/session/media/mediasession.h" | |
51 #include "webrtc/base/gunit.h" | |
52 #include "webrtc/base/physicalsocketserver.h" | |
53 #include "webrtc/base/scoped_ptr.h" | |
54 #include "webrtc/base/ssladapter.h" | |
55 #include "webrtc/base/sslstreamadapter.h" | |
56 #include "webrtc/base/thread.h" | |
57 #include "webrtc/base/virtualsocketserver.h" | |
58 #include "webrtc/media/webrtc/fakewebrtcvideoengine.h" | |
59 #include "webrtc/p2p/base/constants.h" | |
60 #include "webrtc/p2p/base/sessiondescription.h" | |
61 #include "webrtc/p2p/client/fakeportallocator.h" | |
62 | |
63 #define MAYBE_SKIP_TEST(feature) \ | |
64 if (!(feature())) { \ | |
65 LOG(LS_INFO) << "Feature disabled... skipping"; \ | |
66 return; \ | |
67 } | |
68 | |
69 using cricket::ContentInfo; | |
70 using cricket::FakeWebRtcVideoDecoder; | |
71 using cricket::FakeWebRtcVideoDecoderFactory; | |
72 using cricket::FakeWebRtcVideoEncoder; | |
73 using cricket::FakeWebRtcVideoEncoderFactory; | |
74 using cricket::MediaContentDescription; | |
75 using webrtc::DataBuffer; | |
76 using webrtc::DataChannelInterface; | |
77 using webrtc::DtmfSender; | |
78 using webrtc::DtmfSenderInterface; | |
79 using webrtc::DtmfSenderObserverInterface; | |
80 using webrtc::FakeConstraints; | |
81 using webrtc::MediaConstraintsInterface; | |
82 using webrtc::MediaStreamInterface; | |
83 using webrtc::MediaStreamTrackInterface; | |
84 using webrtc::MockCreateSessionDescriptionObserver; | |
85 using webrtc::MockDataChannelObserver; | |
86 using webrtc::MockSetSessionDescriptionObserver; | |
87 using webrtc::MockStatsObserver; | |
88 using webrtc::ObserverInterface; | |
89 using webrtc::PeerConnectionInterface; | |
90 using webrtc::PeerConnectionFactory; | |
91 using webrtc::SessionDescriptionInterface; | |
92 using webrtc::StreamCollectionInterface; | |
93 | |
94 static const int kMaxWaitMs = 10000; | |
95 // Disable for TSan v2, see | |
96 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | |
97 // This declaration is also #ifdef'd as it causes uninitialized-variable | |
98 // warnings. | |
99 #if !defined(THREAD_SANITIZER) | |
100 static const int kMaxWaitForStatsMs = 3000; | |
101 #endif | |
102 static const int kMaxWaitForActivationMs = 5000; | |
103 static const int kMaxWaitForFramesMs = 10000; | |
104 static const int kEndAudioFrameCount = 3; | |
105 static const int kEndVideoFrameCount = 3; | |
106 | |
107 static const char kStreamLabelBase[] = "stream_label"; | |
108 static const char kVideoTrackLabelBase[] = "video_track"; | |
109 static const char kAudioTrackLabelBase[] = "audio_track"; | |
110 static const char kDataChannelLabel[] = "data_channel"; | |
111 | |
112 // Disable for TSan v2, see | |
113 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | |
114 // This declaration is also #ifdef'd as it causes unused-variable errors. | |
115 #if !defined(THREAD_SANITIZER) | |
116 // SRTP cipher name negotiated by the tests. This must be updated if the | |
117 // default changes. | |
118 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; | |
119 #endif | |
120 | |
121 static void RemoveLinesFromSdp(const std::string& line_start, | |
122 std::string* sdp) { | |
123 const char kSdpLineEnd[] = "\r\n"; | |
124 size_t ssrc_pos = 0; | |
125 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != | |
126 std::string::npos) { | |
127 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); | |
128 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); | |
129 } | |
130 } | |
131 | |
132 class SignalingMessageReceiver { | |
133 public: | |
134 virtual void ReceiveSdpMessage(const std::string& type, | |
135 std::string& msg) = 0; | |
136 virtual void ReceiveIceMessage(const std::string& sdp_mid, | |
137 int sdp_mline_index, | |
138 const std::string& msg) = 0; | |
139 | |
140 protected: | |
141 SignalingMessageReceiver() {} | |
142 virtual ~SignalingMessageReceiver() {} | |
143 }; | |
144 | |
145 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, | |
146 public SignalingMessageReceiver, | |
147 public ObserverInterface { | |
148 public: | |
149 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( | |
150 const std::string& id, | |
151 const MediaConstraintsInterface* constraints, | |
152 const PeerConnectionFactory::Options* options, | |
153 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | |
154 PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); | |
155 if (!client->Init(constraints, options, std::move(dtls_identity_store))) { | |
156 delete client; | |
157 return nullptr; | |
158 } | |
159 return client; | |
160 } | |
161 | |
162 static PeerConnectionTestClient* CreateClient( | |
163 const std::string& id, | |
164 const MediaConstraintsInterface* constraints, | |
165 const PeerConnectionFactory::Options* options) { | |
166 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( | |
167 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | |
168 : nullptr); | |
169 | |
170 return CreateClientWithDtlsIdentityStore(id, constraints, options, | |
171 std::move(dtls_identity_store)); | |
172 } | |
173 | |
174 ~PeerConnectionTestClient() { | |
175 } | |
176 | |
177 void Negotiate() { Negotiate(true, true); } | |
178 | |
179 void Negotiate(bool audio, bool video) { | |
180 rtc::scoped_ptr<SessionDescriptionInterface> offer; | |
181 ASSERT_TRUE(DoCreateOffer(offer.use())); | |
182 | |
183 if (offer->description()->GetContentByName("audio")) { | |
184 offer->description()->GetContentByName("audio")->rejected = !audio; | |
185 } | |
186 if (offer->description()->GetContentByName("video")) { | |
187 offer->description()->GetContentByName("video")->rejected = !video; | |
188 } | |
189 | |
190 std::string sdp; | |
191 EXPECT_TRUE(offer->ToString(&sdp)); | |
192 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
193 signaling_message_receiver_->ReceiveSdpMessage( | |
194 webrtc::SessionDescriptionInterface::kOffer, sdp); | |
195 } | |
196 | |
197 // SignalingMessageReceiver callback. | |
198 void ReceiveSdpMessage(const std::string& type, std::string& msg) override { | |
199 FilterIncomingSdpMessage(&msg); | |
200 if (type == webrtc::SessionDescriptionInterface::kOffer) { | |
201 HandleIncomingOffer(msg); | |
202 } else { | |
203 HandleIncomingAnswer(msg); | |
204 } | |
205 } | |
206 | |
207 // SignalingMessageReceiver callback. | |
208 void ReceiveIceMessage(const std::string& sdp_mid, | |
209 int sdp_mline_index, | |
210 const std::string& msg) override { | |
211 LOG(INFO) << id_ << "ReceiveIceMessage"; | |
212 rtc::scoped_ptr<webrtc::IceCandidateInterface> candidate( | |
213 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr)); | |
214 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); | |
215 } | |
216 | |
217 // PeerConnectionObserver callbacks. | |
218 void OnSignalingChange( | |
219 webrtc::PeerConnectionInterface::SignalingState new_state) override { | |
220 EXPECT_EQ(pc()->signaling_state(), new_state); | |
221 } | |
222 void OnAddStream(MediaStreamInterface* media_stream) override { | |
223 media_stream->RegisterObserver(this); | |
224 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) { | |
225 const std::string id = media_stream->GetVideoTracks()[i]->id(); | |
226 ASSERT_TRUE(fake_video_renderers_.find(id) == | |
227 fake_video_renderers_.end()); | |
228 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer( | |
229 media_stream->GetVideoTracks()[i])); | |
230 } | |
231 } | |
232 void OnRemoveStream(MediaStreamInterface* media_stream) override {} | |
233 void OnRenegotiationNeeded() override {} | |
234 void OnIceConnectionChange( | |
235 webrtc::PeerConnectionInterface::IceConnectionState new_state) override { | |
236 EXPECT_EQ(pc()->ice_connection_state(), new_state); | |
237 } | |
238 void OnIceGatheringChange( | |
239 webrtc::PeerConnectionInterface::IceGatheringState new_state) override { | |
240 EXPECT_EQ(pc()->ice_gathering_state(), new_state); | |
241 } | |
242 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { | |
243 LOG(INFO) << id_ << "OnIceCandidate"; | |
244 | |
245 std::string ice_sdp; | |
246 EXPECT_TRUE(candidate->ToString(&ice_sdp)); | |
247 if (signaling_message_receiver_ == nullptr) { | |
248 // Remote party may be deleted. | |
249 return; | |
250 } | |
251 signaling_message_receiver_->ReceiveIceMessage( | |
252 candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); | |
253 } | |
254 | |
255 // MediaStreamInterface callback | |
256 void OnChanged() override { | |
257 // Track added or removed from MediaStream, so update our renderers. | |
258 rtc::scoped_refptr<StreamCollectionInterface> remote_streams = | |
259 pc()->remote_streams(); | |
260 // Remove renderers for tracks that were removed. | |
261 for (auto it = fake_video_renderers_.begin(); | |
262 it != fake_video_renderers_.end();) { | |
263 if (remote_streams->FindVideoTrack(it->first) == nullptr) { | |
264 auto to_remove = it++; | |
265 removed_fake_video_renderers_.push_back(std::move(to_remove->second)); | |
266 fake_video_renderers_.erase(to_remove); | |
267 } else { | |
268 ++it; | |
269 } | |
270 } | |
271 // Create renderers for new video tracks. | |
272 for (size_t stream_index = 0; stream_index < remote_streams->count(); | |
273 ++stream_index) { | |
274 MediaStreamInterface* remote_stream = remote_streams->at(stream_index); | |
275 for (size_t track_index = 0; | |
276 track_index < remote_stream->GetVideoTracks().size(); | |
277 ++track_index) { | |
278 const std::string id = | |
279 remote_stream->GetVideoTracks()[track_index]->id(); | |
280 if (fake_video_renderers_.find(id) != fake_video_renderers_.end()) { | |
281 continue; | |
282 } | |
283 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer( | |
284 remote_stream->GetVideoTracks()[track_index])); | |
285 } | |
286 } | |
287 } | |
288 | |
289 void SetVideoConstraints(const webrtc::FakeConstraints& video_constraint) { | |
290 video_constraints_ = video_constraint; | |
291 } | |
292 | |
293 void AddMediaStream(bool audio, bool video) { | |
294 std::string stream_label = | |
295 kStreamLabelBase + | |
296 rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); | |
297 rtc::scoped_refptr<MediaStreamInterface> stream = | |
298 peer_connection_factory_->CreateLocalMediaStream(stream_label); | |
299 | |
300 if (audio && can_receive_audio()) { | |
301 stream->AddTrack(CreateLocalAudioTrack(stream_label)); | |
302 } | |
303 if (video && can_receive_video()) { | |
304 stream->AddTrack(CreateLocalVideoTrack(stream_label)); | |
305 } | |
306 | |
307 EXPECT_TRUE(pc()->AddStream(stream)); | |
308 } | |
309 | |
310 size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } | |
311 | |
312 bool SessionActive() { | |
313 return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable; | |
314 } | |
315 | |
316 // Automatically add a stream when receiving an offer, if we don't have one. | |
317 // Defaults to true. | |
318 void set_auto_add_stream(bool auto_add_stream) { | |
319 auto_add_stream_ = auto_add_stream; | |
320 } | |
321 | |
322 void set_signaling_message_receiver( | |
323 SignalingMessageReceiver* signaling_message_receiver) { | |
324 signaling_message_receiver_ = signaling_message_receiver; | |
325 } | |
326 | |
327 void EnableVideoDecoderFactory() { | |
328 video_decoder_factory_enabled_ = true; | |
329 fake_video_decoder_factory_->AddSupportedVideoCodecType( | |
330 webrtc::kVideoCodecVP8); | |
331 } | |
332 | |
333 void IceRestart() { | |
334 session_description_constraints_.SetMandatoryIceRestart(true); | |
335 SetExpectIceRestart(true); | |
336 } | |
337 | |
338 void SetExpectIceRestart(bool expect_restart) { | |
339 expect_ice_restart_ = expect_restart; | |
340 } | |
341 | |
342 bool ExpectIceRestart() const { return expect_ice_restart_; } | |
343 | |
344 void SetReceiveAudioVideo(bool audio, bool video) { | |
345 SetReceiveAudio(audio); | |
346 SetReceiveVideo(video); | |
347 ASSERT_EQ(audio, can_receive_audio()); | |
348 ASSERT_EQ(video, can_receive_video()); | |
349 } | |
350 | |
351 void SetReceiveAudio(bool audio) { | |
352 if (audio && can_receive_audio()) | |
353 return; | |
354 session_description_constraints_.SetMandatoryReceiveAudio(audio); | |
355 } | |
356 | |
357 void SetReceiveVideo(bool video) { | |
358 if (video && can_receive_video()) | |
359 return; | |
360 session_description_constraints_.SetMandatoryReceiveVideo(video); | |
361 } | |
362 | |
363 void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; } | |
364 | |
365 void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; } | |
366 | |
367 void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; } | |
368 | |
369 bool can_receive_audio() { | |
370 bool value; | |
371 if (webrtc::FindConstraint(&session_description_constraints_, | |
372 MediaConstraintsInterface::kOfferToReceiveAudio, | |
373 &value, nullptr)) { | |
374 return value; | |
375 } | |
376 return true; | |
377 } | |
378 | |
379 bool can_receive_video() { | |
380 bool value; | |
381 if (webrtc::FindConstraint(&session_description_constraints_, | |
382 MediaConstraintsInterface::kOfferToReceiveVideo, | |
383 &value, nullptr)) { | |
384 return value; | |
385 } | |
386 return true; | |
387 } | |
388 | |
389 void OnDataChannel(DataChannelInterface* data_channel) override { | |
390 LOG(INFO) << id_ << "OnDataChannel"; | |
391 data_channel_ = data_channel; | |
392 data_observer_.reset(new MockDataChannelObserver(data_channel)); | |
393 } | |
394 | |
395 void CreateDataChannel() { | |
396 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, nullptr); | |
397 ASSERT_TRUE(data_channel_.get() != nullptr); | |
398 data_observer_.reset(new MockDataChannelObserver(data_channel_)); | |
399 } | |
400 | |
401 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( | |
402 const std::string& stream_label) { | |
403 FakeConstraints constraints; | |
404 // Disable highpass filter so that we can get all the test audio frames. | |
405 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); | |
406 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = | |
407 peer_connection_factory_->CreateAudioSource(&constraints); | |
408 // TODO(perkj): Test audio source when it is implemented. Currently audio | |
409 // always use the default input. | |
410 std::string label = stream_label + kAudioTrackLabelBase; | |
411 return peer_connection_factory_->CreateAudioTrack(label, source); | |
412 } | |
413 | |
414 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( | |
415 const std::string& stream_label) { | |
416 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. | |
417 FakeConstraints source_constraints = video_constraints_; | |
418 source_constraints.SetMandatoryMaxFrameRate(10); | |
419 | |
420 cricket::FakeVideoCapturer* fake_capturer = | |
421 new webrtc::FakePeriodicVideoCapturer(); | |
422 video_capturers_.push_back(fake_capturer); | |
423 rtc::scoped_refptr<webrtc::VideoSourceInterface> source = | |
424 peer_connection_factory_->CreateVideoSource(fake_capturer, | |
425 &source_constraints); | |
426 std::string label = stream_label + kVideoTrackLabelBase; | |
427 return peer_connection_factory_->CreateVideoTrack(label, source); | |
428 } | |
429 | |
430 DataChannelInterface* data_channel() { return data_channel_; } | |
431 const MockDataChannelObserver* data_observer() const { | |
432 return data_observer_.get(); | |
433 } | |
434 | |
435 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } | |
436 | |
437 void StopVideoCapturers() { | |
438 for (std::vector<cricket::VideoCapturer*>::iterator it = | |
439 video_capturers_.begin(); | |
440 it != video_capturers_.end(); ++it) { | |
441 (*it)->Stop(); | |
442 } | |
443 } | |
444 | |
445 bool AudioFramesReceivedCheck(int number_of_frames) const { | |
446 return number_of_frames <= fake_audio_capture_module_->frames_received(); | |
447 } | |
448 | |
449 int audio_frames_received() const { | |
450 return fake_audio_capture_module_->frames_received(); | |
451 } | |
452 | |
453 bool VideoFramesReceivedCheck(int number_of_frames) { | |
454 if (video_decoder_factory_enabled_) { | |
455 const std::vector<FakeWebRtcVideoDecoder*>& decoders | |
456 = fake_video_decoder_factory_->decoders(); | |
457 if (decoders.empty()) { | |
458 return number_of_frames <= 0; | |
459 } | |
460 | |
461 for (FakeWebRtcVideoDecoder* decoder : decoders) { | |
462 if (number_of_frames > decoder->GetNumFramesReceived()) { | |
463 return false; | |
464 } | |
465 } | |
466 return true; | |
467 } else { | |
468 if (fake_video_renderers_.empty()) { | |
469 return number_of_frames <= 0; | |
470 } | |
471 | |
472 for (const auto& pair : fake_video_renderers_) { | |
473 if (number_of_frames > pair.second->num_rendered_frames()) { | |
474 return false; | |
475 } | |
476 } | |
477 return true; | |
478 } | |
479 } | |
480 | |
481 int video_frames_received() const { | |
482 int total = 0; | |
483 if (video_decoder_factory_enabled_) { | |
484 const std::vector<FakeWebRtcVideoDecoder*>& decoders = | |
485 fake_video_decoder_factory_->decoders(); | |
486 for (const FakeWebRtcVideoDecoder* decoder : decoders) { | |
487 total += decoder->GetNumFramesReceived(); | |
488 } | |
489 } else { | |
490 for (const auto& pair : fake_video_renderers_) { | |
491 total += pair.second->num_rendered_frames(); | |
492 } | |
493 for (const auto& renderer : removed_fake_video_renderers_) { | |
494 total += renderer->num_rendered_frames(); | |
495 } | |
496 } | |
497 return total; | |
498 } | |
499 | |
500 // Verify the CreateDtmfSender interface | |
501 void VerifyDtmf() { | |
502 rtc::scoped_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver()); | |
503 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender; | |
504 | |
505 // We can't create a DTMF sender with an invalid audio track or a non local | |
506 // track. | |
507 EXPECT_TRUE(peer_connection_->CreateDtmfSender(nullptr) == nullptr); | |
508 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack( | |
509 peer_connection_factory_->CreateAudioTrack("dummy_track", nullptr)); | |
510 EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == nullptr); | |
511 | |
512 // We should be able to create a DTMF sender from a local track. | |
513 webrtc::AudioTrackInterface* localtrack = | |
514 peer_connection_->local_streams()->at(0)->GetAudioTracks()[0]; | |
515 dtmf_sender = peer_connection_->CreateDtmfSender(localtrack); | |
516 EXPECT_TRUE(dtmf_sender.get() != nullptr); | |
517 dtmf_sender->RegisterObserver(observer.get()); | |
518 | |
519 // Test the DtmfSender object just created. | |
520 EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); | |
521 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); | |
522 | |
523 // We don't need to verify that the DTMF tones are actually sent out because | |
524 // that is already covered by the tests of the lower level components. | |
525 | |
526 EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs); | |
527 std::vector<std::string> tones; | |
528 tones.push_back("1"); | |
529 tones.push_back("a"); | |
530 tones.push_back(""); | |
531 observer->Verify(tones); | |
532 | |
533 dtmf_sender->UnregisterObserver(); | |
534 } | |
535 | |
536 // Verifies that the SessionDescription have rejected the appropriate media | |
537 // content. | |
538 void VerifyRejectedMediaInSessionDescription() { | |
539 ASSERT_TRUE(peer_connection_->remote_description() != nullptr); | |
540 ASSERT_TRUE(peer_connection_->local_description() != nullptr); | |
541 const cricket::SessionDescription* remote_desc = | |
542 peer_connection_->remote_description()->description(); | |
543 const cricket::SessionDescription* local_desc = | |
544 peer_connection_->local_description()->description(); | |
545 | |
546 const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc); | |
547 if (remote_audio_content) { | |
548 const ContentInfo* audio_content = | |
549 GetFirstAudioContent(local_desc); | |
550 EXPECT_EQ(can_receive_audio(), !audio_content->rejected); | |
551 } | |
552 | |
553 const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc); | |
554 if (remote_video_content) { | |
555 const ContentInfo* video_content = | |
556 GetFirstVideoContent(local_desc); | |
557 EXPECT_EQ(can_receive_video(), !video_content->rejected); | |
558 } | |
559 } | |
560 | |
561 void VerifyLocalIceUfragAndPassword() { | |
562 ASSERT_TRUE(peer_connection_->local_description() != nullptr); | |
563 const cricket::SessionDescription* desc = | |
564 peer_connection_->local_description()->description(); | |
565 const cricket::ContentInfos& contents = desc->contents(); | |
566 | |
567 for (size_t index = 0; index < contents.size(); ++index) { | |
568 if (contents[index].rejected) | |
569 continue; | |
570 const cricket::TransportDescription* transport_desc = | |
571 desc->GetTransportDescriptionByName(contents[index].name); | |
572 | |
573 std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it = | |
574 ice_ufrag_pwd_.find(static_cast<int>(index)); | |
575 if (ufragpair_it == ice_ufrag_pwd_.end()) { | |
576 ASSERT_FALSE(ExpectIceRestart()); | |
577 ice_ufrag_pwd_[static_cast<int>(index)] = | |
578 IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd); | |
579 } else if (ExpectIceRestart()) { | |
580 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second; | |
581 EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag); | |
582 EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd); | |
583 } else { | |
584 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second; | |
585 EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag); | |
586 EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd); | |
587 } | |
588 } | |
589 } | |
590 | |
591 int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) { | |
592 rtc::scoped_refptr<MockStatsObserver> | |
593 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
594 EXPECT_TRUE(peer_connection_->GetStats( | |
595 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
596 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
597 EXPECT_NE(0, observer->timestamp()); | |
598 return observer->AudioOutputLevel(); | |
599 } | |
600 | |
601 int GetAudioInputLevelStats() { | |
602 rtc::scoped_refptr<MockStatsObserver> | |
603 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
604 EXPECT_TRUE(peer_connection_->GetStats( | |
605 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
606 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
607 EXPECT_NE(0, observer->timestamp()); | |
608 return observer->AudioInputLevel(); | |
609 } | |
610 | |
611 int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) { | |
612 rtc::scoped_refptr<MockStatsObserver> | |
613 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
614 EXPECT_TRUE(peer_connection_->GetStats( | |
615 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
616 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
617 EXPECT_NE(0, observer->timestamp()); | |
618 return observer->BytesReceived(); | |
619 } | |
620 | |
621 int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) { | |
622 rtc::scoped_refptr<MockStatsObserver> | |
623 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
624 EXPECT_TRUE(peer_connection_->GetStats( | |
625 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
626 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
627 EXPECT_NE(0, observer->timestamp()); | |
628 return observer->BytesSent(); | |
629 } | |
630 | |
631 int GetAvailableReceivedBandwidthStats() { | |
632 rtc::scoped_refptr<MockStatsObserver> | |
633 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
634 EXPECT_TRUE(peer_connection_->GetStats( | |
635 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
636 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
637 EXPECT_NE(0, observer->timestamp()); | |
638 int bw = observer->AvailableReceiveBandwidth(); | |
639 return bw; | |
640 } | |
641 | |
642 std::string GetDtlsCipherStats() { | |
643 rtc::scoped_refptr<MockStatsObserver> | |
644 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
645 EXPECT_TRUE(peer_connection_->GetStats( | |
646 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
647 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
648 EXPECT_NE(0, observer->timestamp()); | |
649 return observer->DtlsCipher(); | |
650 } | |
651 | |
652 std::string GetSrtpCipherStats() { | |
653 rtc::scoped_refptr<MockStatsObserver> | |
654 observer(new rtc::RefCountedObject<MockStatsObserver>()); | |
655 EXPECT_TRUE(peer_connection_->GetStats( | |
656 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); | |
657 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
658 EXPECT_NE(0, observer->timestamp()); | |
659 return observer->SrtpCipher(); | |
660 } | |
661 | |
662 int rendered_width() { | |
663 EXPECT_FALSE(fake_video_renderers_.empty()); | |
664 return fake_video_renderers_.empty() ? 1 : | |
665 fake_video_renderers_.begin()->second->width(); | |
666 } | |
667 | |
668 int rendered_height() { | |
669 EXPECT_FALSE(fake_video_renderers_.empty()); | |
670 return fake_video_renderers_.empty() ? 1 : | |
671 fake_video_renderers_.begin()->second->height(); | |
672 } | |
673 | |
674 size_t number_of_remote_streams() { | |
675 if (!pc()) | |
676 return 0; | |
677 return pc()->remote_streams()->count(); | |
678 } | |
679 | |
680 StreamCollectionInterface* remote_streams() { | |
681 if (!pc()) { | |
682 ADD_FAILURE(); | |
683 return nullptr; | |
684 } | |
685 return pc()->remote_streams(); | |
686 } | |
687 | |
688 StreamCollectionInterface* local_streams() { | |
689 if (!pc()) { | |
690 ADD_FAILURE(); | |
691 return nullptr; | |
692 } | |
693 return pc()->local_streams(); | |
694 } | |
695 | |
696 webrtc::PeerConnectionInterface::SignalingState signaling_state() { | |
697 return pc()->signaling_state(); | |
698 } | |
699 | |
700 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { | |
701 return pc()->ice_connection_state(); | |
702 } | |
703 | |
704 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { | |
705 return pc()->ice_gathering_state(); | |
706 } | |
707 | |
708 private: | |
709 class DummyDtmfObserver : public DtmfSenderObserverInterface { | |
710 public: | |
711 DummyDtmfObserver() : completed_(false) {} | |
712 | |
713 // Implements DtmfSenderObserverInterface. | |
714 void OnToneChange(const std::string& tone) override { | |
715 tones_.push_back(tone); | |
716 if (tone.empty()) { | |
717 completed_ = true; | |
718 } | |
719 } | |
720 | |
721 void Verify(const std::vector<std::string>& tones) const { | |
722 ASSERT_TRUE(tones_.size() == tones.size()); | |
723 EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin())); | |
724 } | |
725 | |
726 bool completed() const { return completed_; } | |
727 | |
728 private: | |
729 bool completed_; | |
730 std::vector<std::string> tones_; | |
731 }; | |
732 | |
733 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} | |
734 | |
735 bool Init( | |
736 const MediaConstraintsInterface* constraints, | |
737 const PeerConnectionFactory::Options* options, | |
738 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | |
739 EXPECT_TRUE(!peer_connection_); | |
740 EXPECT_TRUE(!peer_connection_factory_); | |
741 rtc::scoped_ptr<cricket::PortAllocator> port_allocator( | |
742 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | |
743 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); | |
744 | |
745 if (fake_audio_capture_module_ == nullptr) { | |
746 return false; | |
747 } | |
748 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); | |
749 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); | |
750 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( | |
751 rtc::Thread::Current(), rtc::Thread::Current(), | |
752 fake_audio_capture_module_, fake_video_encoder_factory_, | |
753 fake_video_decoder_factory_); | |
754 if (!peer_connection_factory_) { | |
755 return false; | |
756 } | |
757 if (options) { | |
758 peer_connection_factory_->SetOptions(*options); | |
759 } | |
760 peer_connection_ = CreatePeerConnection( | |
761 std::move(port_allocator), constraints, std::move(dtls_identity_store)); | |
762 return peer_connection_.get() != nullptr; | |
763 } | |
764 | |
765 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | |
766 rtc::scoped_ptr<cricket::PortAllocator> port_allocator, | |
767 const MediaConstraintsInterface* constraints, | |
768 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | |
769 // CreatePeerConnection with RTCConfiguration. | |
770 webrtc::PeerConnectionInterface::RTCConfiguration config; | |
771 webrtc::PeerConnectionInterface::IceServer ice_server; | |
772 ice_server.uri = "stun:stun.l.google.com:19302"; | |
773 config.servers.push_back(ice_server); | |
774 | |
775 return peer_connection_factory_->CreatePeerConnection( | |
776 config, constraints, std::move(port_allocator), | |
777 std::move(dtls_identity_store), this); | |
778 } | |
779 | |
780 void HandleIncomingOffer(const std::string& msg) { | |
781 LOG(INFO) << id_ << "HandleIncomingOffer "; | |
782 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { | |
783 // If we are not sending any streams ourselves it is time to add some. | |
784 AddMediaStream(true, true); | |
785 } | |
786 rtc::scoped_ptr<SessionDescriptionInterface> desc( | |
787 webrtc::CreateSessionDescription("offer", msg, nullptr)); | |
788 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); | |
789 rtc::scoped_ptr<SessionDescriptionInterface> answer; | |
790 EXPECT_TRUE(DoCreateAnswer(answer.use())); | |
791 std::string sdp; | |
792 EXPECT_TRUE(answer->ToString(&sdp)); | |
793 EXPECT_TRUE(DoSetLocalDescription(answer.release())); | |
794 if (signaling_message_receiver_) { | |
795 signaling_message_receiver_->ReceiveSdpMessage( | |
796 webrtc::SessionDescriptionInterface::kAnswer, sdp); | |
797 } | |
798 } | |
799 | |
800 void HandleIncomingAnswer(const std::string& msg) { | |
801 LOG(INFO) << id_ << "HandleIncomingAnswer"; | |
802 rtc::scoped_ptr<SessionDescriptionInterface> desc( | |
803 webrtc::CreateSessionDescription("answer", msg, nullptr)); | |
804 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); | |
805 } | |
806 | |
807 bool DoCreateOfferAnswer(SessionDescriptionInterface** desc, | |
808 bool offer) { | |
809 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> | |
810 observer(new rtc::RefCountedObject< | |
811 MockCreateSessionDescriptionObserver>()); | |
812 if (offer) { | |
813 pc()->CreateOffer(observer, &session_description_constraints_); | |
814 } else { | |
815 pc()->CreateAnswer(observer, &session_description_constraints_); | |
816 } | |
817 EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs); | |
818 *desc = observer->release_desc(); | |
819 if (observer->result() && ExpectIceRestart()) { | |
820 EXPECT_EQ(0u, (*desc)->candidates(0)->count()); | |
821 } | |
822 return observer->result(); | |
823 } | |
824 | |
825 bool DoCreateOffer(SessionDescriptionInterface** desc) { | |
826 return DoCreateOfferAnswer(desc, true); | |
827 } | |
828 | |
829 bool DoCreateAnswer(SessionDescriptionInterface** desc) { | |
830 return DoCreateOfferAnswer(desc, false); | |
831 } | |
832 | |
833 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { | |
834 rtc::scoped_refptr<MockSetSessionDescriptionObserver> | |
835 observer(new rtc::RefCountedObject< | |
836 MockSetSessionDescriptionObserver>()); | |
837 LOG(INFO) << id_ << "SetLocalDescription "; | |
838 pc()->SetLocalDescription(observer, desc); | |
839 // Ignore the observer result. If we wait for the result with | |
840 // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer | |
841 // before the offer which is an error. | |
842 // The reason is that EXPECT_TRUE_WAIT uses | |
843 // rtc::Thread::Current()->ProcessMessages(1); | |
844 // ProcessMessages waits at least 1ms but processes all messages before | |
845 // returning. Since this test is synchronous and send messages to the remote | |
846 // peer whenever a callback is invoked, this can lead to messages being | |
847 // sent to the remote peer in the wrong order. | |
848 // TODO(perkj): Find a way to check the result without risking that the | |
849 // order of sent messages are changed. Ex- by posting all messages that are | |
850 // sent to the remote peer. | |
851 return true; | |
852 } | |
853 | |
854 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { | |
855 rtc::scoped_refptr<MockSetSessionDescriptionObserver> | |
856 observer(new rtc::RefCountedObject< | |
857 MockSetSessionDescriptionObserver>()); | |
858 LOG(INFO) << id_ << "SetRemoteDescription "; | |
859 pc()->SetRemoteDescription(observer, desc); | |
860 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); | |
861 return observer->result(); | |
862 } | |
863 | |
864 // This modifies all received SDP messages before they are processed. | |
865 void FilterIncomingSdpMessage(std::string* sdp) { | |
866 if (remove_msid_) { | |
867 const char kSdpSsrcAttribute[] = "a=ssrc:"; | |
868 RemoveLinesFromSdp(kSdpSsrcAttribute, sdp); | |
869 const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:"; | |
870 RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp); | |
871 } | |
872 if (remove_bundle_) { | |
873 const char kSdpBundleAttribute[] = "a=group:BUNDLE"; | |
874 RemoveLinesFromSdp(kSdpBundleAttribute, sdp); | |
875 } | |
876 if (remove_sdes_) { | |
877 const char kSdpSdesCryptoAttribute[] = "a=crypto"; | |
878 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); | |
879 } | |
880 } | |
881 | |
882 std::string id_; | |
883 | |
884 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | |
885 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> | |
886 peer_connection_factory_; | |
887 | |
888 bool auto_add_stream_ = true; | |
889 | |
890 typedef std::pair<std::string, std::string> IceUfragPwdPair; | |
891 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; | |
892 bool expect_ice_restart_ = false; | |
893 | |
894 // Needed to keep track of number of frames sent. | |
895 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; | |
896 // Needed to keep track of number of frames received. | |
897 std::map<std::string, rtc::scoped_ptr<webrtc::FakeVideoTrackRenderer>> | |
898 fake_video_renderers_; | |
899 // Needed to ensure frames aren't received for removed tracks. | |
900 std::vector<rtc::scoped_ptr<webrtc::FakeVideoTrackRenderer>> | |
901 removed_fake_video_renderers_; | |
902 // Needed to keep track of number of frames received when external decoder | |
903 // used. | |
904 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr; | |
905 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr; | |
906 bool video_decoder_factory_enabled_ = false; | |
907 webrtc::FakeConstraints video_constraints_; | |
908 | |
909 // For remote peer communication. | |
910 SignalingMessageReceiver* signaling_message_receiver_ = nullptr; | |
911 | |
912 // Store references to the video capturers we've created, so that we can stop | |
913 // them, if required. | |
914 std::vector<cricket::VideoCapturer*> video_capturers_; | |
915 | |
916 webrtc::FakeConstraints session_description_constraints_; | |
917 bool remove_msid_ = false; // True if MSID should be removed in received SDP. | |
918 bool remove_bundle_ = | |
919 false; // True if bundle should be removed in received SDP. | |
920 bool remove_sdes_ = | |
921 false; // True if a=crypto should be removed in received SDP. | |
922 | |
923 rtc::scoped_refptr<DataChannelInterface> data_channel_; | |
924 rtc::scoped_ptr<MockDataChannelObserver> data_observer_; | |
925 }; | |
926 | |
927 class P2PTestConductor : public testing::Test { | |
928 public: | |
929 P2PTestConductor() | |
930 : pss_(new rtc::PhysicalSocketServer), | |
931 ss_(new rtc::VirtualSocketServer(pss_.get())), | |
932 ss_scope_(ss_.get()) {} | |
933 | |
934 bool SessionActive() { | |
935 return initiating_client_->SessionActive() && | |
936 receiving_client_->SessionActive(); | |
937 } | |
938 | |
939 // Return true if the number of frames provided have been received or it is | |
940 // known that that will never occur (e.g. no frames will be sent or | |
941 // captured). | |
942 bool FramesNotPending(int audio_frames_to_receive, | |
943 int video_frames_to_receive) { | |
944 return VideoFramesReceivedCheck(video_frames_to_receive) && | |
945 AudioFramesReceivedCheck(audio_frames_to_receive); | |
946 } | |
947 bool AudioFramesReceivedCheck(int frames_received) { | |
948 return initiating_client_->AudioFramesReceivedCheck(frames_received) && | |
949 receiving_client_->AudioFramesReceivedCheck(frames_received); | |
950 } | |
951 bool VideoFramesReceivedCheck(int frames_received) { | |
952 return initiating_client_->VideoFramesReceivedCheck(frames_received) && | |
953 receiving_client_->VideoFramesReceivedCheck(frames_received); | |
954 } | |
955 void VerifyDtmf() { | |
956 initiating_client_->VerifyDtmf(); | |
957 receiving_client_->VerifyDtmf(); | |
958 } | |
959 | |
960 void TestUpdateOfferWithRejectedContent() { | |
961 // Renegotiate, rejecting the video m-line. | |
962 initiating_client_->Negotiate(true, false); | |
963 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | |
964 | |
965 int pc1_audio_received = initiating_client_->audio_frames_received(); | |
966 int pc1_video_received = initiating_client_->video_frames_received(); | |
967 int pc2_audio_received = receiving_client_->audio_frames_received(); | |
968 int pc2_video_received = receiving_client_->video_frames_received(); | |
969 | |
970 // Wait for some additional audio frames to be received. | |
971 EXPECT_TRUE_WAIT(initiating_client_->AudioFramesReceivedCheck( | |
972 pc1_audio_received + kEndAudioFrameCount) && | |
973 receiving_client_->AudioFramesReceivedCheck( | |
974 pc2_audio_received + kEndAudioFrameCount), | |
975 kMaxWaitForFramesMs); | |
976 | |
977 // During this time, we shouldn't have received any additional video frames | |
978 // for the rejected video tracks. | |
979 EXPECT_EQ(pc1_video_received, initiating_client_->video_frames_received()); | |
980 EXPECT_EQ(pc2_video_received, receiving_client_->video_frames_received()); | |
981 } | |
982 | |
983 void VerifyRenderedSize(int width, int height) { | |
984 EXPECT_EQ(width, receiving_client()->rendered_width()); | |
985 EXPECT_EQ(height, receiving_client()->rendered_height()); | |
986 EXPECT_EQ(width, initializing_client()->rendered_width()); | |
987 EXPECT_EQ(height, initializing_client()->rendered_height()); | |
988 } | |
989 | |
990 void VerifySessionDescriptions() { | |
991 initiating_client_->VerifyRejectedMediaInSessionDescription(); | |
992 receiving_client_->VerifyRejectedMediaInSessionDescription(); | |
993 initiating_client_->VerifyLocalIceUfragAndPassword(); | |
994 receiving_client_->VerifyLocalIceUfragAndPassword(); | |
995 } | |
996 | |
997 ~P2PTestConductor() { | |
998 if (initiating_client_) { | |
999 initiating_client_->set_signaling_message_receiver(nullptr); | |
1000 } | |
1001 if (receiving_client_) { | |
1002 receiving_client_->set_signaling_message_receiver(nullptr); | |
1003 } | |
1004 } | |
1005 | |
1006 bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } | |
1007 | |
1008 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | |
1009 MediaConstraintsInterface* recv_constraints) { | |
1010 return CreateTestClients(init_constraints, nullptr, recv_constraints, | |
1011 nullptr); | |
1012 } | |
1013 | |
1014 void SetSignalingReceivers() { | |
1015 initiating_client_->set_signaling_message_receiver(receiving_client_.get()); | |
1016 receiving_client_->set_signaling_message_receiver(initiating_client_.get()); | |
1017 } | |
1018 | |
1019 bool CreateTestClients(MediaConstraintsInterface* init_constraints, | |
1020 PeerConnectionFactory::Options* init_options, | |
1021 MediaConstraintsInterface* recv_constraints, | |
1022 PeerConnectionFactory::Options* recv_options) { | |
1023 initiating_client_.reset(PeerConnectionTestClient::CreateClient( | |
1024 "Caller: ", init_constraints, init_options)); | |
1025 receiving_client_.reset(PeerConnectionTestClient::CreateClient( | |
1026 "Callee: ", recv_constraints, recv_options)); | |
1027 if (!initiating_client_ || !receiving_client_) { | |
1028 return false; | |
1029 } | |
1030 SetSignalingReceivers(); | |
1031 return true; | |
1032 } | |
1033 | |
1034 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, | |
1035 const webrtc::FakeConstraints& recv_constraints) { | |
1036 initiating_client_->SetVideoConstraints(init_constraints); | |
1037 receiving_client_->SetVideoConstraints(recv_constraints); | |
1038 } | |
1039 | |
1040 void EnableVideoDecoderFactory() { | |
1041 initiating_client_->EnableVideoDecoderFactory(); | |
1042 receiving_client_->EnableVideoDecoderFactory(); | |
1043 } | |
1044 | |
1045 // This test sets up a call between two parties. Both parties send static | |
1046 // frames to each other. Once the test is finished the number of sent frames | |
1047 // is compared to the number of received frames. | |
1048 void LocalP2PTest() { | |
1049 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { | |
1050 initiating_client_->AddMediaStream(true, true); | |
1051 } | |
1052 initiating_client_->Negotiate(); | |
1053 // Assert true is used here since next tests are guaranteed to fail and | |
1054 // would eat up 5 seconds. | |
1055 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | |
1056 VerifySessionDescriptions(); | |
1057 | |
1058 int audio_frame_count = kEndAudioFrameCount; | |
1059 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. | |
1060 if (!initiating_client_->can_receive_audio() || | |
1061 !receiving_client_->can_receive_audio()) { | |
1062 audio_frame_count = -1; | |
1063 } | |
1064 int video_frame_count = kEndVideoFrameCount; | |
1065 if (!initiating_client_->can_receive_video() || | |
1066 !receiving_client_->can_receive_video()) { | |
1067 video_frame_count = -1; | |
1068 } | |
1069 | |
1070 if (audio_frame_count != -1 || video_frame_count != -1) { | |
1071 // Audio or video is expected to flow, so both clients should reach the | |
1072 // Connected state, and the offerer (ICE controller) should proceed to | |
1073 // Completed. | |
1074 // Note: These tests have been observed to fail under heavy load at | |
1075 // shorter timeouts, so they may be flaky. | |
1076 EXPECT_EQ_WAIT( | |
1077 webrtc::PeerConnectionInterface::kIceConnectionCompleted, | |
1078 initiating_client_->ice_connection_state(), | |
1079 kMaxWaitForFramesMs); | |
1080 EXPECT_EQ_WAIT( | |
1081 webrtc::PeerConnectionInterface::kIceConnectionConnected, | |
1082 receiving_client_->ice_connection_state(), | |
1083 kMaxWaitForFramesMs); | |
1084 } | |
1085 | |
1086 if (initiating_client_->can_receive_audio() || | |
1087 initiating_client_->can_receive_video()) { | |
1088 // The initiating client can receive media, so it must produce candidates | |
1089 // that will serve as destinations for that media. | |
1090 // TODO(bemasc): Understand why the state is not already Complete here, as | |
1091 // seems to be the case for the receiving client. This may indicate a bug | |
1092 // in the ICE gathering system. | |
1093 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew, | |
1094 initiating_client_->ice_gathering_state()); | |
1095 } | |
1096 if (receiving_client_->can_receive_audio() || | |
1097 receiving_client_->can_receive_video()) { | |
1098 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, | |
1099 receiving_client_->ice_gathering_state(), | |
1100 kMaxWaitForFramesMs); | |
1101 } | |
1102 | |
1103 EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count), | |
1104 kMaxWaitForFramesMs); | |
1105 } | |
1106 | |
1107 void SetupAndVerifyDtlsCall() { | |
1108 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1109 FakeConstraints setup_constraints; | |
1110 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, | |
1111 true); | |
1112 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1113 LocalP2PTest(); | |
1114 VerifyRenderedSize(640, 480); | |
1115 } | |
1116 | |
1117 PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() { | |
1118 FakeConstraints setup_constraints; | |
1119 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, | |
1120 true); | |
1121 | |
1122 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( | |
1123 rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore() | |
1124 : nullptr); | |
1125 dtls_identity_store->use_alternate_key(); | |
1126 | |
1127 // Make sure the new client is using a different certificate. | |
1128 return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( | |
1129 "New Peer: ", &setup_constraints, nullptr, | |
1130 std::move(dtls_identity_store)); | |
1131 } | |
1132 | |
1133 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { | |
1134 // Messages may get lost on the unreliable DataChannel, so we send multiple | |
1135 // times to avoid test flakiness. | |
1136 static const size_t kSendAttempts = 5; | |
1137 | |
1138 for (size_t i = 0; i < kSendAttempts; ++i) { | |
1139 dc->Send(DataBuffer(data)); | |
1140 } | |
1141 } | |
1142 | |
1143 PeerConnectionTestClient* initializing_client() { | |
1144 return initiating_client_.get(); | |
1145 } | |
1146 | |
1147 // Set the |initiating_client_| to the |client| passed in and return the | |
1148 // original |initiating_client_|. | |
1149 PeerConnectionTestClient* set_initializing_client( | |
1150 PeerConnectionTestClient* client) { | |
1151 PeerConnectionTestClient* old = initiating_client_.release(); | |
1152 initiating_client_.reset(client); | |
1153 return old; | |
1154 } | |
1155 | |
1156 PeerConnectionTestClient* receiving_client() { | |
1157 return receiving_client_.get(); | |
1158 } | |
1159 | |
1160 // Set the |receiving_client_| to the |client| passed in and return the | |
1161 // original |receiving_client_|. | |
1162 PeerConnectionTestClient* set_receiving_client( | |
1163 PeerConnectionTestClient* client) { | |
1164 PeerConnectionTestClient* old = receiving_client_.release(); | |
1165 receiving_client_.reset(client); | |
1166 return old; | |
1167 } | |
1168 | |
1169 private: | |
1170 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | |
1171 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | |
1172 rtc::SocketServerScope ss_scope_; | |
1173 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; | |
1174 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; | |
1175 }; | |
1176 | |
1177 // Disable for TSan v2, see | |
1178 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | |
1179 #if !defined(THREAD_SANITIZER) | |
1180 | |
1181 // This test sets up a Jsep call between two parties and test Dtmf. | |
1182 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | |
1183 // See issue webrtc/2378. | |
1184 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) { | |
1185 ASSERT_TRUE(CreateTestClients()); | |
1186 LocalP2PTest(); | |
1187 VerifyDtmf(); | |
1188 } | |
1189 | |
1190 // This test sets up a Jsep call between two parties and test that we can get a | |
1191 // video aspect ratio of 16:9. | |
1192 TEST_F(P2PTestConductor, LocalP2PTest16To9) { | |
1193 ASSERT_TRUE(CreateTestClients()); | |
1194 FakeConstraints constraint; | |
1195 double requested_ratio = 640.0/360; | |
1196 constraint.SetMandatoryMinAspectRatio(requested_ratio); | |
1197 SetVideoConstraints(constraint, constraint); | |
1198 LocalP2PTest(); | |
1199 | |
1200 ASSERT_LE(0, initializing_client()->rendered_height()); | |
1201 double initiating_video_ratio = | |
1202 static_cast<double>(initializing_client()->rendered_width()) / | |
1203 initializing_client()->rendered_height(); | |
1204 EXPECT_LE(requested_ratio, initiating_video_ratio); | |
1205 | |
1206 ASSERT_LE(0, receiving_client()->rendered_height()); | |
1207 double receiving_video_ratio = | |
1208 static_cast<double>(receiving_client()->rendered_width()) / | |
1209 receiving_client()->rendered_height(); | |
1210 EXPECT_LE(requested_ratio, receiving_video_ratio); | |
1211 } | |
1212 | |
1213 // This test sets up a Jsep call between two parties and test that the | |
1214 // received video has a resolution of 1280*720. | |
1215 // TODO(mallinath): Enable when | |
1216 // http://code.google.com/p/webrtc/issues/detail?id=981 is fixed. | |
1217 TEST_F(P2PTestConductor, DISABLED_LocalP2PTest1280By720) { | |
1218 ASSERT_TRUE(CreateTestClients()); | |
1219 FakeConstraints constraint; | |
1220 constraint.SetMandatoryMinWidth(1280); | |
1221 constraint.SetMandatoryMinHeight(720); | |
1222 SetVideoConstraints(constraint, constraint); | |
1223 LocalP2PTest(); | |
1224 VerifyRenderedSize(1280, 720); | |
1225 } | |
1226 | |
1227 // This test sets up a call between two endpoints that are configured to use | |
1228 // DTLS key agreement. As a result, DTLS is negotiated and used for transport. | |
1229 TEST_F(P2PTestConductor, LocalP2PTestDtls) { | |
1230 SetupAndVerifyDtlsCall(); | |
1231 } | |
1232 | |
1233 // This test sets up a audio call initially and then upgrades to audio/video, | |
1234 // using DTLS. | |
1235 TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) { | |
1236 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1237 FakeConstraints setup_constraints; | |
1238 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, | |
1239 true); | |
1240 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1241 receiving_client()->SetReceiveAudioVideo(true, false); | |
1242 LocalP2PTest(); | |
1243 receiving_client()->SetReceiveAudioVideo(true, true); | |
1244 receiving_client()->Negotiate(); | |
1245 } | |
1246 | |
1247 // This test sets up a call transfer to a new caller with a different DTLS | |
1248 // fingerprint. | |
1249 TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCallee) { | |
1250 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1251 SetupAndVerifyDtlsCall(); | |
1252 | |
1253 // Keeping the original peer around which will still send packets to the | |
1254 // receiving client. These SRTP packets will be dropped. | |
1255 rtc::scoped_ptr<PeerConnectionTestClient> original_peer( | |
1256 set_initializing_client(CreateDtlsClientWithAlternateKey())); | |
1257 original_peer->pc()->Close(); | |
1258 | |
1259 SetSignalingReceivers(); | |
1260 receiving_client()->SetExpectIceRestart(true); | |
1261 LocalP2PTest(); | |
1262 VerifyRenderedSize(640, 480); | |
1263 } | |
1264 | |
1265 // This test sets up a non-bundle call and apply bundle during ICE restart. When | |
1266 // bundle is in effect in the restart, the channel can successfully reset its | |
1267 // DTLS-SRTP context. | |
1268 TEST_F(P2PTestConductor, LocalP2PTestDtlsBundleInIceRestart) { | |
1269 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1270 FakeConstraints setup_constraints; | |
1271 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, | |
1272 true); | |
1273 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1274 receiving_client()->RemoveBundleFromReceivedSdp(true); | |
1275 LocalP2PTest(); | |
1276 VerifyRenderedSize(640, 480); | |
1277 | |
1278 initializing_client()->IceRestart(); | |
1279 receiving_client()->SetExpectIceRestart(true); | |
1280 receiving_client()->RemoveBundleFromReceivedSdp(false); | |
1281 LocalP2PTest(); | |
1282 VerifyRenderedSize(640, 480); | |
1283 } | |
1284 | |
1285 // This test sets up a call transfer to a new callee with a different DTLS | |
1286 // fingerprint. | |
1287 TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCaller) { | |
1288 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1289 SetupAndVerifyDtlsCall(); | |
1290 | |
1291 // Keeping the original peer around which will still send packets to the | |
1292 // receiving client. These SRTP packets will be dropped. | |
1293 rtc::scoped_ptr<PeerConnectionTestClient> original_peer( | |
1294 set_receiving_client(CreateDtlsClientWithAlternateKey())); | |
1295 original_peer->pc()->Close(); | |
1296 | |
1297 SetSignalingReceivers(); | |
1298 initializing_client()->IceRestart(); | |
1299 LocalP2PTest(); | |
1300 VerifyRenderedSize(640, 480); | |
1301 } | |
1302 | |
1303 // This test sets up a call between two endpoints that are configured to use | |
1304 // DTLS key agreement. The offerer don't support SDES. As a result, DTLS is | |
1305 // negotiated and used for transport. | |
1306 TEST_F(P2PTestConductor, LocalP2PTestOfferDtlsButNotSdes) { | |
1307 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1308 FakeConstraints setup_constraints; | |
1309 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, | |
1310 true); | |
1311 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1312 receiving_client()->RemoveSdesCryptoFromReceivedSdp(true); | |
1313 LocalP2PTest(); | |
1314 VerifyRenderedSize(640, 480); | |
1315 } | |
1316 | |
1317 // This test sets up a Jsep call between two parties, and the callee only | |
1318 // accept to receive video. | |
1319 TEST_F(P2PTestConductor, LocalP2PTestAnswerVideo) { | |
1320 ASSERT_TRUE(CreateTestClients()); | |
1321 receiving_client()->SetReceiveAudioVideo(false, true); | |
1322 LocalP2PTest(); | |
1323 } | |
1324 | |
1325 // This test sets up a Jsep call between two parties, and the callee only | |
1326 // accept to receive audio. | |
1327 TEST_F(P2PTestConductor, LocalP2PTestAnswerAudio) { | |
1328 ASSERT_TRUE(CreateTestClients()); | |
1329 receiving_client()->SetReceiveAudioVideo(true, false); | |
1330 LocalP2PTest(); | |
1331 } | |
1332 | |
1333 // This test sets up a Jsep call between two parties, and the callee reject both | |
1334 // audio and video. | |
1335 TEST_F(P2PTestConductor, LocalP2PTestAnswerNone) { | |
1336 ASSERT_TRUE(CreateTestClients()); | |
1337 receiving_client()->SetReceiveAudioVideo(false, false); | |
1338 LocalP2PTest(); | |
1339 } | |
1340 | |
1341 // This test sets up an audio and video call between two parties. After the call | |
1342 // runs for a while (10 frames), the caller sends an update offer with video | |
1343 // being rejected. Once the re-negotiation is done, the video flow should stop | |
1344 // and the audio flow should continue. | |
1345 TEST_F(P2PTestConductor, UpdateOfferWithRejectedContent) { | |
1346 ASSERT_TRUE(CreateTestClients()); | |
1347 LocalP2PTest(); | |
1348 TestUpdateOfferWithRejectedContent(); | |
1349 } | |
1350 | |
1351 // This test sets up a Jsep call between two parties. The MSID is removed from | |
1352 // the SDP strings from the caller. | |
1353 TEST_F(P2PTestConductor, LocalP2PTestWithoutMsid) { | |
1354 ASSERT_TRUE(CreateTestClients()); | |
1355 receiving_client()->RemoveMsidFromReceivedSdp(true); | |
1356 // TODO(perkj): Currently there is a bug that cause audio to stop playing if | |
1357 // audio and video is muxed when MSID is disabled. Remove | |
1358 // SetRemoveBundleFromSdp once | |
1359 // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed. | |
1360 receiving_client()->RemoveBundleFromReceivedSdp(true); | |
1361 LocalP2PTest(); | |
1362 } | |
1363 | |
1364 // This test sets up a Jsep call between two parties and the initiating peer | |
1365 // sends two steams. | |
1366 // TODO(perkj): Disabled due to | |
1367 // https://code.google.com/p/webrtc/issues/detail?id=1454 | |
1368 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestTwoStreams) { | |
1369 ASSERT_TRUE(CreateTestClients()); | |
1370 // Set optional video constraint to max 320pixels to decrease CPU usage. | |
1371 FakeConstraints constraint; | |
1372 constraint.SetOptionalMaxWidth(320); | |
1373 SetVideoConstraints(constraint, constraint); | |
1374 initializing_client()->AddMediaStream(true, true); | |
1375 initializing_client()->AddMediaStream(false, true); | |
1376 ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams()); | |
1377 LocalP2PTest(); | |
1378 EXPECT_EQ(2u, receiving_client()->number_of_remote_streams()); | |
1379 } | |
1380 | |
1381 // Test that we can receive the audio output level from a remote audio track. | |
1382 TEST_F(P2PTestConductor, GetAudioOutputLevelStats) { | |
1383 ASSERT_TRUE(CreateTestClients()); | |
1384 LocalP2PTest(); | |
1385 | |
1386 StreamCollectionInterface* remote_streams = | |
1387 initializing_client()->remote_streams(); | |
1388 ASSERT_GT(remote_streams->count(), 0u); | |
1389 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); | |
1390 MediaStreamTrackInterface* remote_audio_track = | |
1391 remote_streams->at(0)->GetAudioTracks()[0]; | |
1392 | |
1393 // Get the audio output level stats. Note that the level is not available | |
1394 // until a RTCP packet has been received. | |
1395 EXPECT_TRUE_WAIT( | |
1396 initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0, | |
1397 kMaxWaitForStatsMs); | |
1398 } | |
1399 | |
1400 // Test that an audio input level is reported. | |
1401 TEST_F(P2PTestConductor, GetAudioInputLevelStats) { | |
1402 ASSERT_TRUE(CreateTestClients()); | |
1403 LocalP2PTest(); | |
1404 | |
1405 // Get the audio input level stats. The level should be available very | |
1406 // soon after the test starts. | |
1407 EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0, | |
1408 kMaxWaitForStatsMs); | |
1409 } | |
1410 | |
1411 // Test that we can get incoming byte counts from both audio and video tracks. | |
1412 TEST_F(P2PTestConductor, GetBytesReceivedStats) { | |
1413 ASSERT_TRUE(CreateTestClients()); | |
1414 LocalP2PTest(); | |
1415 | |
1416 StreamCollectionInterface* remote_streams = | |
1417 initializing_client()->remote_streams(); | |
1418 ASSERT_GT(remote_streams->count(), 0u); | |
1419 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); | |
1420 MediaStreamTrackInterface* remote_audio_track = | |
1421 remote_streams->at(0)->GetAudioTracks()[0]; | |
1422 EXPECT_TRUE_WAIT( | |
1423 initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0, | |
1424 kMaxWaitForStatsMs); | |
1425 | |
1426 MediaStreamTrackInterface* remote_video_track = | |
1427 remote_streams->at(0)->GetVideoTracks()[0]; | |
1428 EXPECT_TRUE_WAIT( | |
1429 initializing_client()->GetBytesReceivedStats(remote_video_track) > 0, | |
1430 kMaxWaitForStatsMs); | |
1431 } | |
1432 | |
1433 // Test that we can get outgoing byte counts from both audio and video tracks. | |
1434 TEST_F(P2PTestConductor, GetBytesSentStats) { | |
1435 ASSERT_TRUE(CreateTestClients()); | |
1436 LocalP2PTest(); | |
1437 | |
1438 StreamCollectionInterface* local_streams = | |
1439 initializing_client()->local_streams(); | |
1440 ASSERT_GT(local_streams->count(), 0u); | |
1441 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u); | |
1442 MediaStreamTrackInterface* local_audio_track = | |
1443 local_streams->at(0)->GetAudioTracks()[0]; | |
1444 EXPECT_TRUE_WAIT( | |
1445 initializing_client()->GetBytesSentStats(local_audio_track) > 0, | |
1446 kMaxWaitForStatsMs); | |
1447 | |
1448 MediaStreamTrackInterface* local_video_track = | |
1449 local_streams->at(0)->GetVideoTracks()[0]; | |
1450 EXPECT_TRUE_WAIT( | |
1451 initializing_client()->GetBytesSentStats(local_video_track) > 0, | |
1452 kMaxWaitForStatsMs); | |
1453 } | |
1454 | |
1455 // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. | |
1456 TEST_F(P2PTestConductor, GetDtls12None) { | |
1457 PeerConnectionFactory::Options init_options; | |
1458 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; | |
1459 PeerConnectionFactory::Options recv_options; | |
1460 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; | |
1461 ASSERT_TRUE( | |
1462 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); | |
1463 rtc::scoped_refptr<webrtc::FakeMetricsObserver> | |
1464 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); | |
1465 initializing_client()->pc()->RegisterUMAObserver(init_observer); | |
1466 LocalP2PTest(); | |
1467 | |
1468 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( | |
1469 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1470 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)), | |
1471 initializing_client()->GetDtlsCipherStats(), | |
1472 kMaxWaitForStatsMs); | |
1473 EXPECT_EQ(1, init_observer->GetEnumCounter( | |
1474 webrtc::kEnumCounterAudioSslCipher, | |
1475 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1476 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); | |
1477 | |
1478 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), | |
1479 initializing_client()->GetSrtpCipherStats(), | |
1480 kMaxWaitForStatsMs); | |
1481 EXPECT_EQ(1, | |
1482 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, | |
1483 kDefaultSrtpCryptoSuite)); | |
1484 } | |
1485 | |
1486 // Test that DTLS 1.2 is used if both ends support it. | |
1487 TEST_F(P2PTestConductor, GetDtls12Both) { | |
1488 PeerConnectionFactory::Options init_options; | |
1489 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; | |
1490 PeerConnectionFactory::Options recv_options; | |
1491 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; | |
1492 ASSERT_TRUE( | |
1493 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); | |
1494 rtc::scoped_refptr<webrtc::FakeMetricsObserver> | |
1495 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); | |
1496 initializing_client()->pc()->RegisterUMAObserver(init_observer); | |
1497 LocalP2PTest(); | |
1498 | |
1499 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( | |
1500 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1501 rtc::SSL_PROTOCOL_DTLS_12, rtc::KT_DEFAULT)), | |
1502 initializing_client()->GetDtlsCipherStats(), | |
1503 kMaxWaitForStatsMs); | |
1504 EXPECT_EQ(1, init_observer->GetEnumCounter( | |
1505 webrtc::kEnumCounterAudioSslCipher, | |
1506 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1507 rtc::SSL_PROTOCOL_DTLS_12, rtc::KT_DEFAULT))); | |
1508 | |
1509 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), | |
1510 initializing_client()->GetSrtpCipherStats(), | |
1511 kMaxWaitForStatsMs); | |
1512 EXPECT_EQ(1, | |
1513 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, | |
1514 kDefaultSrtpCryptoSuite)); | |
1515 } | |
1516 | |
1517 // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the | |
1518 // received supports 1.0. | |
1519 TEST_F(P2PTestConductor, GetDtls12Init) { | |
1520 PeerConnectionFactory::Options init_options; | |
1521 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; | |
1522 PeerConnectionFactory::Options recv_options; | |
1523 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; | |
1524 ASSERT_TRUE( | |
1525 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); | |
1526 rtc::scoped_refptr<webrtc::FakeMetricsObserver> | |
1527 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); | |
1528 initializing_client()->pc()->RegisterUMAObserver(init_observer); | |
1529 LocalP2PTest(); | |
1530 | |
1531 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( | |
1532 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1533 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)), | |
1534 initializing_client()->GetDtlsCipherStats(), | |
1535 kMaxWaitForStatsMs); | |
1536 EXPECT_EQ(1, init_observer->GetEnumCounter( | |
1537 webrtc::kEnumCounterAudioSslCipher, | |
1538 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1539 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); | |
1540 | |
1541 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), | |
1542 initializing_client()->GetSrtpCipherStats(), | |
1543 kMaxWaitForStatsMs); | |
1544 EXPECT_EQ(1, | |
1545 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, | |
1546 kDefaultSrtpCryptoSuite)); | |
1547 } | |
1548 | |
1549 // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the | |
1550 // received supports 1.2. | |
1551 TEST_F(P2PTestConductor, GetDtls12Recv) { | |
1552 PeerConnectionFactory::Options init_options; | |
1553 init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; | |
1554 PeerConnectionFactory::Options recv_options; | |
1555 recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; | |
1556 ASSERT_TRUE( | |
1557 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); | |
1558 rtc::scoped_refptr<webrtc::FakeMetricsObserver> | |
1559 init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); | |
1560 initializing_client()->pc()->RegisterUMAObserver(init_observer); | |
1561 LocalP2PTest(); | |
1562 | |
1563 EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( | |
1564 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1565 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)), | |
1566 initializing_client()->GetDtlsCipherStats(), | |
1567 kMaxWaitForStatsMs); | |
1568 EXPECT_EQ(1, init_observer->GetEnumCounter( | |
1569 webrtc::kEnumCounterAudioSslCipher, | |
1570 rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | |
1571 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); | |
1572 | |
1573 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), | |
1574 initializing_client()->GetSrtpCipherStats(), | |
1575 kMaxWaitForStatsMs); | |
1576 EXPECT_EQ(1, | |
1577 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, | |
1578 kDefaultSrtpCryptoSuite)); | |
1579 } | |
1580 | |
1581 // This test sets up a call between two parties with audio, video and an RTP | |
1582 // data channel. | |
1583 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) { | |
1584 FakeConstraints setup_constraints; | |
1585 setup_constraints.SetAllowRtpDataChannels(); | |
1586 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1587 initializing_client()->CreateDataChannel(); | |
1588 LocalP2PTest(); | |
1589 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); | |
1590 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); | |
1591 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), | |
1592 kMaxWaitMs); | |
1593 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), | |
1594 kMaxWaitMs); | |
1595 | |
1596 std::string data = "hello world"; | |
1597 | |
1598 SendRtpData(initializing_client()->data_channel(), data); | |
1599 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), | |
1600 kMaxWaitMs); | |
1601 | |
1602 SendRtpData(receiving_client()->data_channel(), data); | |
1603 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), | |
1604 kMaxWaitMs); | |
1605 | |
1606 receiving_client()->data_channel()->Close(); | |
1607 // Send new offer and answer. | |
1608 receiving_client()->Negotiate(); | |
1609 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); | |
1610 EXPECT_FALSE(receiving_client()->data_observer()->IsOpen()); | |
1611 } | |
1612 | |
1613 // This test sets up a call between two parties with audio, video and an SCTP | |
1614 // data channel. | |
1615 TEST_F(P2PTestConductor, LocalP2PTestSctpDataChannel) { | |
1616 ASSERT_TRUE(CreateTestClients()); | |
1617 initializing_client()->CreateDataChannel(); | |
1618 LocalP2PTest(); | |
1619 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); | |
1620 EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs); | |
1621 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), | |
1622 kMaxWaitMs); | |
1623 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); | |
1624 | |
1625 std::string data = "hello world"; | |
1626 | |
1627 initializing_client()->data_channel()->Send(DataBuffer(data)); | |
1628 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), | |
1629 kMaxWaitMs); | |
1630 | |
1631 receiving_client()->data_channel()->Send(DataBuffer(data)); | |
1632 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), | |
1633 kMaxWaitMs); | |
1634 | |
1635 receiving_client()->data_channel()->Close(); | |
1636 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(), | |
1637 kMaxWaitMs); | |
1638 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); | |
1639 } | |
1640 | |
1641 // This test sets up a call between two parties and creates a data channel. | |
1642 // The test tests that received data is buffered unless an observer has been | |
1643 // registered. | |
1644 // Rtp data channels can receive data before the underlying | |
1645 // transport has detected that a channel is writable and thus data can be | |
1646 // received before the data channel state changes to open. That is hard to test | |
1647 // but the same buffering is used in that case. | |
1648 TEST_F(P2PTestConductor, RegisterDataChannelObserver) { | |
1649 FakeConstraints setup_constraints; | |
1650 setup_constraints.SetAllowRtpDataChannels(); | |
1651 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1652 initializing_client()->CreateDataChannel(); | |
1653 initializing_client()->Negotiate(); | |
1654 | |
1655 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); | |
1656 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); | |
1657 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), | |
1658 kMaxWaitMs); | |
1659 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, | |
1660 receiving_client()->data_channel()->state(), kMaxWaitMs); | |
1661 | |
1662 // Unregister the existing observer. | |
1663 receiving_client()->data_channel()->UnregisterObserver(); | |
1664 | |
1665 std::string data = "hello world"; | |
1666 SendRtpData(initializing_client()->data_channel(), data); | |
1667 | |
1668 // Wait a while to allow the sent data to arrive before an observer is | |
1669 // registered.. | |
1670 rtc::Thread::Current()->ProcessMessages(100); | |
1671 | |
1672 MockDataChannelObserver new_observer(receiving_client()->data_channel()); | |
1673 EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs); | |
1674 } | |
1675 | |
1676 // This test sets up a call between two parties with audio, video and but only | |
1677 // the initiating client support data. | |
1678 TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportData) { | |
1679 FakeConstraints setup_constraints_1; | |
1680 setup_constraints_1.SetAllowRtpDataChannels(); | |
1681 // Must disable DTLS to make negotiation succeed. | |
1682 setup_constraints_1.SetMandatory( | |
1683 MediaConstraintsInterface::kEnableDtlsSrtp, false); | |
1684 FakeConstraints setup_constraints_2; | |
1685 setup_constraints_2.SetMandatory( | |
1686 MediaConstraintsInterface::kEnableDtlsSrtp, false); | |
1687 ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2)); | |
1688 initializing_client()->CreateDataChannel(); | |
1689 LocalP2PTest(); | |
1690 EXPECT_TRUE(initializing_client()->data_channel() != nullptr); | |
1691 EXPECT_FALSE(receiving_client()->data_channel()); | |
1692 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); | |
1693 } | |
1694 | |
1695 // This test sets up a call between two parties with audio, video. When audio | |
1696 // and video is setup and flowing and data channel is negotiated. | |
1697 TEST_F(P2PTestConductor, AddDataChannelAfterRenegotiation) { | |
1698 FakeConstraints setup_constraints; | |
1699 setup_constraints.SetAllowRtpDataChannels(); | |
1700 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | |
1701 LocalP2PTest(); | |
1702 initializing_client()->CreateDataChannel(); | |
1703 // Send new offer and answer. | |
1704 initializing_client()->Negotiate(); | |
1705 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); | |
1706 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); | |
1707 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), | |
1708 kMaxWaitMs); | |
1709 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), | |
1710 kMaxWaitMs); | |
1711 } | |
1712 | |
1713 // This test sets up a Jsep call with SCTP DataChannel and verifies the | |
1714 // negotiation is completed without error. | |
1715 #ifdef HAVE_SCTP | |
1716 TEST_F(P2PTestConductor, CreateOfferWithSctpDataChannel) { | |
1717 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
1718 FakeConstraints constraints; | |
1719 constraints.SetMandatory( | |
1720 MediaConstraintsInterface::kEnableDtlsSrtp, true); | |
1721 ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); | |
1722 initializing_client()->CreateDataChannel(); | |
1723 initializing_client()->Negotiate(false, false); | |
1724 } | |
1725 #endif | |
1726 | |
1727 // This test sets up a call between two parties with audio, and video. | |
1728 // During the call, the initializing side restart ice and the test verifies that | |
1729 // new ice candidates are generated and audio and video still can flow. | |
1730 TEST_F(P2PTestConductor, IceRestart) { | |
1731 ASSERT_TRUE(CreateTestClients()); | |
1732 | |
1733 // Negotiate and wait for ice completion and make sure audio and video plays. | |
1734 LocalP2PTest(); | |
1735 | |
1736 // Create a SDP string of the first audio candidate for both clients. | |
1737 const webrtc::IceCandidateCollection* audio_candidates_initiator = | |
1738 initializing_client()->pc()->local_description()->candidates(0); | |
1739 const webrtc::IceCandidateCollection* audio_candidates_receiver = | |
1740 receiving_client()->pc()->local_description()->candidates(0); | |
1741 ASSERT_GT(audio_candidates_initiator->count(), 0u); | |
1742 ASSERT_GT(audio_candidates_receiver->count(), 0u); | |
1743 std::string initiator_candidate; | |
1744 EXPECT_TRUE( | |
1745 audio_candidates_initiator->at(0)->ToString(&initiator_candidate)); | |
1746 std::string receiver_candidate; | |
1747 EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate)); | |
1748 | |
1749 // Restart ice on the initializing client. | |
1750 receiving_client()->SetExpectIceRestart(true); | |
1751 initializing_client()->IceRestart(); | |
1752 | |
1753 // Negotiate and wait for ice completion again and make sure audio and video | |
1754 // plays. | |
1755 LocalP2PTest(); | |
1756 | |
1757 // Create a SDP string of the first audio candidate for both clients again. | |
1758 const webrtc::IceCandidateCollection* audio_candidates_initiator_restart = | |
1759 initializing_client()->pc()->local_description()->candidates(0); | |
1760 const webrtc::IceCandidateCollection* audio_candidates_reciever_restart = | |
1761 receiving_client()->pc()->local_description()->candidates(0); | |
1762 ASSERT_GT(audio_candidates_initiator_restart->count(), 0u); | |
1763 ASSERT_GT(audio_candidates_reciever_restart->count(), 0u); | |
1764 std::string initiator_candidate_restart; | |
1765 EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString( | |
1766 &initiator_candidate_restart)); | |
1767 std::string receiver_candidate_restart; | |
1768 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString( | |
1769 &receiver_candidate_restart)); | |
1770 | |
1771 // Verify that the first candidates in the local session descriptions has | |
1772 // changed. | |
1773 EXPECT_NE(initiator_candidate, initiator_candidate_restart); | |
1774 EXPECT_NE(receiver_candidate, receiver_candidate_restart); | |
1775 } | |
1776 | |
1777 // This test sets up a call between two parties with audio, and video. | |
1778 // It then renegotiates setting the video m-line to "port 0", then later | |
1779 // renegotiates again, enabling video. | |
1780 TEST_F(P2PTestConductor, LocalP2PTestVideoDisableEnable) { | |
1781 ASSERT_TRUE(CreateTestClients()); | |
1782 | |
1783 // Do initial negotiation. Will result in video and audio sendonly m-lines. | |
1784 receiving_client()->set_auto_add_stream(false); | |
1785 initializing_client()->AddMediaStream(true, true); | |
1786 initializing_client()->Negotiate(); | |
1787 | |
1788 // Negotiate again, disabling the video m-line (receiving client will | |
1789 // set port to 0 due to mandatory "OfferToReceiveVideo: false" constraint). | |
1790 receiving_client()->SetReceiveVideo(false); | |
1791 initializing_client()->Negotiate(); | |
1792 | |
1793 // Enable video and do negotiation again, making sure video is received | |
1794 // end-to-end. | |
1795 receiving_client()->SetReceiveVideo(true); | |
1796 receiving_client()->AddMediaStream(true, true); | |
1797 LocalP2PTest(); | |
1798 } | |
1799 | |
1800 // This test sets up a Jsep call between two parties with external | |
1801 // VideoDecoderFactory. | |
1802 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | |
1803 // See issue webrtc/2378. | |
1804 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) { | |
1805 ASSERT_TRUE(CreateTestClients()); | |
1806 EnableVideoDecoderFactory(); | |
1807 LocalP2PTest(); | |
1808 } | |
1809 | |
1810 // This tests that if we negotiate after calling CreateSender but before we | |
1811 // have a track, then set a track later, frames from the newly-set track are | |
1812 // received end-to-end. | |
1813 TEST_F(P2PTestConductor, EarlyWarmupTest) { | |
1814 ASSERT_TRUE(CreateTestClients()); | |
1815 auto audio_sender = | |
1816 initializing_client()->pc()->CreateSender("audio", "stream_id"); | |
1817 auto video_sender = | |
1818 initializing_client()->pc()->CreateSender("video", "stream_id"); | |
1819 initializing_client()->Negotiate(); | |
1820 // Wait for ICE connection to complete, without any tracks. | |
1821 // Note that the receiving client WILL (in HandleIncomingOffer) create | |
1822 // tracks, so it's only the initiator here that's doing early warmup. | |
1823 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); | |
1824 VerifySessionDescriptions(); | |
1825 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, | |
1826 initializing_client()->ice_connection_state(), | |
1827 kMaxWaitForFramesMs); | |
1828 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, | |
1829 receiving_client()->ice_connection_state(), | |
1830 kMaxWaitForFramesMs); | |
1831 // Now set the tracks, and expect frames to immediately start flowing. | |
1832 EXPECT_TRUE( | |
1833 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); | |
1834 EXPECT_TRUE( | |
1835 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); | |
1836 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount), | |
1837 kMaxWaitForFramesMs); | |
1838 } | |
1839 | |
1840 class IceServerParsingTest : public testing::Test { | |
1841 public: | |
1842 // Convenience for parsing a single URL. | |
1843 bool ParseUrl(const std::string& url) { | |
1844 return ParseUrl(url, std::string(), std::string()); | |
1845 } | |
1846 | |
1847 bool ParseUrl(const std::string& url, | |
1848 const std::string& username, | |
1849 const std::string& password) { | |
1850 PeerConnectionInterface::IceServers servers; | |
1851 PeerConnectionInterface::IceServer server; | |
1852 server.urls.push_back(url); | |
1853 server.username = username; | |
1854 server.password = password; | |
1855 servers.push_back(server); | |
1856 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_); | |
1857 } | |
1858 | |
1859 protected: | |
1860 cricket::ServerAddresses stun_servers_; | |
1861 std::vector<cricket::RelayServerConfig> turn_servers_; | |
1862 }; | |
1863 | |
1864 // Make sure all STUN/TURN prefixes are parsed correctly. | |
1865 TEST_F(IceServerParsingTest, ParseStunPrefixes) { | |
1866 EXPECT_TRUE(ParseUrl("stun:hostname")); | |
1867 EXPECT_EQ(1U, stun_servers_.size()); | |
1868 EXPECT_EQ(0U, turn_servers_.size()); | |
1869 stun_servers_.clear(); | |
1870 | |
1871 EXPECT_TRUE(ParseUrl("stuns:hostname")); | |
1872 EXPECT_EQ(1U, stun_servers_.size()); | |
1873 EXPECT_EQ(0U, turn_servers_.size()); | |
1874 stun_servers_.clear(); | |
1875 | |
1876 EXPECT_TRUE(ParseUrl("turn:hostname")); | |
1877 EXPECT_EQ(0U, stun_servers_.size()); | |
1878 EXPECT_EQ(1U, turn_servers_.size()); | |
1879 EXPECT_FALSE(turn_servers_[0].ports[0].secure); | |
1880 turn_servers_.clear(); | |
1881 | |
1882 EXPECT_TRUE(ParseUrl("turns:hostname")); | |
1883 EXPECT_EQ(0U, stun_servers_.size()); | |
1884 EXPECT_EQ(1U, turn_servers_.size()); | |
1885 EXPECT_TRUE(turn_servers_[0].ports[0].secure); | |
1886 turn_servers_.clear(); | |
1887 | |
1888 // invalid prefixes | |
1889 EXPECT_FALSE(ParseUrl("stunn:hostname")); | |
1890 EXPECT_FALSE(ParseUrl(":hostname")); | |
1891 EXPECT_FALSE(ParseUrl(":")); | |
1892 EXPECT_FALSE(ParseUrl("")); | |
1893 } | |
1894 | |
1895 TEST_F(IceServerParsingTest, VerifyDefaults) { | |
1896 // TURNS defaults | |
1897 EXPECT_TRUE(ParseUrl("turns:hostname")); | |
1898 EXPECT_EQ(1U, turn_servers_.size()); | |
1899 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port()); | |
1900 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); | |
1901 turn_servers_.clear(); | |
1902 | |
1903 // TURN defaults | |
1904 EXPECT_TRUE(ParseUrl("turn:hostname")); | |
1905 EXPECT_EQ(1U, turn_servers_.size()); | |
1906 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port()); | |
1907 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); | |
1908 turn_servers_.clear(); | |
1909 | |
1910 // STUN defaults | |
1911 EXPECT_TRUE(ParseUrl("stun:hostname")); | |
1912 EXPECT_EQ(1U, stun_servers_.size()); | |
1913 EXPECT_EQ(3478, stun_servers_.begin()->port()); | |
1914 stun_servers_.clear(); | |
1915 } | |
1916 | |
1917 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port | |
1918 // can be parsed correctly. | |
1919 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { | |
1920 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); | |
1921 EXPECT_EQ(1U, stun_servers_.size()); | |
1922 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); | |
1923 EXPECT_EQ(1234, stun_servers_.begin()->port()); | |
1924 stun_servers_.clear(); | |
1925 | |
1926 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); | |
1927 EXPECT_EQ(1U, stun_servers_.size()); | |
1928 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); | |
1929 EXPECT_EQ(4321, stun_servers_.begin()->port()); | |
1930 stun_servers_.clear(); | |
1931 | |
1932 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); | |
1933 EXPECT_EQ(1U, stun_servers_.size()); | |
1934 EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); | |
1935 EXPECT_EQ(9999, stun_servers_.begin()->port()); | |
1936 stun_servers_.clear(); | |
1937 | |
1938 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); | |
1939 EXPECT_EQ(1U, stun_servers_.size()); | |
1940 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); | |
1941 EXPECT_EQ(3478, stun_servers_.begin()->port()); | |
1942 stun_servers_.clear(); | |
1943 | |
1944 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); | |
1945 EXPECT_EQ(1U, stun_servers_.size()); | |
1946 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); | |
1947 EXPECT_EQ(3478, stun_servers_.begin()->port()); | |
1948 stun_servers_.clear(); | |
1949 | |
1950 EXPECT_TRUE(ParseUrl("stun:hostname")); | |
1951 EXPECT_EQ(1U, stun_servers_.size()); | |
1952 EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); | |
1953 EXPECT_EQ(3478, stun_servers_.begin()->port()); | |
1954 stun_servers_.clear(); | |
1955 | |
1956 // Try some invalid hostname:port strings. | |
1957 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); | |
1958 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); | |
1959 EXPECT_FALSE(ParseUrl("stun:hostname:port:more")); | |
1960 EXPECT_FALSE(ParseUrl("stun:hostname:port more")); | |
1961 EXPECT_FALSE(ParseUrl("stun:hostname:")); | |
1962 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); | |
1963 EXPECT_FALSE(ParseUrl("stun::5555")); | |
1964 EXPECT_FALSE(ParseUrl("stun:")); | |
1965 } | |
1966 | |
1967 // Test parsing the "?transport=xxx" part of the URL. | |
1968 TEST_F(IceServerParsingTest, ParseTransport) { | |
1969 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); | |
1970 EXPECT_EQ(1U, turn_servers_.size()); | |
1971 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); | |
1972 turn_servers_.clear(); | |
1973 | |
1974 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); | |
1975 EXPECT_EQ(1U, turn_servers_.size()); | |
1976 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); | |
1977 turn_servers_.clear(); | |
1978 | |
1979 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); | |
1980 } | |
1981 | |
1982 // Test parsing ICE username contained in URL. | |
1983 TEST_F(IceServerParsingTest, ParseUsername) { | |
1984 EXPECT_TRUE(ParseUrl("turn:user@hostname")); | |
1985 EXPECT_EQ(1U, turn_servers_.size()); | |
1986 EXPECT_EQ("user", turn_servers_[0].credentials.username); | |
1987 turn_servers_.clear(); | |
1988 | |
1989 EXPECT_FALSE(ParseUrl("turn:@hostname")); | |
1990 EXPECT_FALSE(ParseUrl("turn:username@")); | |
1991 EXPECT_FALSE(ParseUrl("turn:@")); | |
1992 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); | |
1993 } | |
1994 | |
1995 // Test that username and password from IceServer is copied into the resulting | |
1996 // RelayServerConfig. | |
1997 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { | |
1998 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); | |
1999 EXPECT_EQ(1U, turn_servers_.size()); | |
2000 EXPECT_EQ("username", turn_servers_[0].credentials.username); | |
2001 EXPECT_EQ("password", turn_servers_[0].credentials.password); | |
2002 } | |
2003 | |
2004 // Ensure that if a server has multiple URLs, each one is parsed. | |
2005 TEST_F(IceServerParsingTest, ParseMultipleUrls) { | |
2006 PeerConnectionInterface::IceServers servers; | |
2007 PeerConnectionInterface::IceServer server; | |
2008 server.urls.push_back("stun:hostname"); | |
2009 server.urls.push_back("turn:hostname"); | |
2010 servers.push_back(server); | |
2011 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | |
2012 EXPECT_EQ(1U, stun_servers_.size()); | |
2013 EXPECT_EQ(1U, turn_servers_.size()); | |
2014 } | |
2015 | |
2016 // Ensure that TURN servers are given unique priorities, | |
2017 // so that their resulting candidates have unique priorities. | |
2018 TEST_F(IceServerParsingTest, TurnServerPrioritiesUnique) { | |
2019 PeerConnectionInterface::IceServers servers; | |
2020 PeerConnectionInterface::IceServer server; | |
2021 server.urls.push_back("turn:hostname"); | |
2022 server.urls.push_back("turn:hostname2"); | |
2023 servers.push_back(server); | |
2024 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | |
2025 EXPECT_EQ(2U, turn_servers_.size()); | |
2026 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | |
2027 } | |
2028 | |
2029 #endif // if !defined(THREAD_SANITIZER) | |
OLD | NEW |