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