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