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