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