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