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