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