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