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