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