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. |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 116 | static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_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 | 5def7b9 | 2015-11-20 11:43:22 -0800 | [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 | 5def7b9 | 2015-11-20 11:43:22 -0800 | [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 | |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 895 | // Flaky on Mac Debug bots. See webrtc:5231 |
| 896 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 897 | #define MAYBE_JsepPeerConnectionP2PTestClient \ |
| 898 | DISABLED_JsepPeerConnectionP2PTestClient |
| 899 | #else |
| 900 | #define MAYBE_JsepPeerConnectionP2PTestClient JsepPeerConnectionP2PTestClient |
| 901 | #endif |
| 902 | |
deadbeef | cbc9507 | 2015-10-15 19:31:56 -0700 | [diff] [blame] | 903 | // TODO(deadbeef): Rename this to P2PTestConductor once the Linux memcheck and |
| 904 | // Windows DrMemory Full bots' blacklists are updated. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 905 | class MAYBE_JsepPeerConnectionP2PTestClient : public testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 906 | public: |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 907 | MAYBE_JsepPeerConnectionP2PTestClient() |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 908 | : pss_(new rtc::PhysicalSocketServer), |
| 909 | ss_(new rtc::VirtualSocketServer(pss_.get())), |
| 910 | ss_scope_(ss_.get()) {} |
| 911 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 912 | bool SessionActive() { |
| 913 | return initiating_client_->SessionActive() && |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 914 | receiving_client_->SessionActive(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 915 | } |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 916 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 917 | // Return true if the number of frames provided have been received or it is |
| 918 | // known that that will never occur (e.g. no frames will be sent or |
| 919 | // captured). |
| 920 | bool FramesNotPending(int audio_frames_to_receive, |
| 921 | int video_frames_to_receive) { |
| 922 | return VideoFramesReceivedCheck(video_frames_to_receive) && |
| 923 | AudioFramesReceivedCheck(audio_frames_to_receive); |
| 924 | } |
| 925 | bool AudioFramesReceivedCheck(int frames_received) { |
| 926 | return initiating_client_->AudioFramesReceivedCheck(frames_received) && |
| 927 | receiving_client_->AudioFramesReceivedCheck(frames_received); |
| 928 | } |
| 929 | bool VideoFramesReceivedCheck(int frames_received) { |
| 930 | return initiating_client_->VideoFramesReceivedCheck(frames_received) && |
| 931 | receiving_client_->VideoFramesReceivedCheck(frames_received); |
| 932 | } |
| 933 | void VerifyDtmf() { |
| 934 | initiating_client_->VerifyDtmf(); |
| 935 | receiving_client_->VerifyDtmf(); |
| 936 | } |
| 937 | |
| 938 | void TestUpdateOfferWithRejectedContent() { |
| 939 | initiating_client_->Negotiate(true, false); |
| 940 | EXPECT_TRUE_WAIT( |
| 941 | FramesNotPending(kEndAudioFrameCount * 2, kEndVideoFrameCount), |
| 942 | kMaxWaitForFramesMs); |
| 943 | // There shouldn't be any more video frame after the new offer is |
| 944 | // negotiated. |
| 945 | EXPECT_FALSE(VideoFramesReceivedCheck(kEndVideoFrameCount + 1)); |
| 946 | } |
| 947 | |
| 948 | void VerifyRenderedSize(int width, int height) { |
| 949 | EXPECT_EQ(width, receiving_client()->rendered_width()); |
| 950 | EXPECT_EQ(height, receiving_client()->rendered_height()); |
| 951 | EXPECT_EQ(width, initializing_client()->rendered_width()); |
| 952 | EXPECT_EQ(height, initializing_client()->rendered_height()); |
| 953 | } |
| 954 | |
| 955 | void VerifySessionDescriptions() { |
| 956 | initiating_client_->VerifyRejectedMediaInSessionDescription(); |
| 957 | receiving_client_->VerifyRejectedMediaInSessionDescription(); |
| 958 | initiating_client_->VerifyLocalIceUfragAndPassword(); |
| 959 | receiving_client_->VerifyLocalIceUfragAndPassword(); |
| 960 | } |
| 961 | |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 962 | ~MAYBE_JsepPeerConnectionP2PTestClient() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 963 | if (initiating_client_) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 964 | initiating_client_->set_signaling_message_receiver(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 965 | } |
| 966 | if (receiving_client_) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 967 | receiving_client_->set_signaling_message_receiver(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 968 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 969 | } |
| 970 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 971 | bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 972 | |
| 973 | bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 974 | MediaConstraintsInterface* recv_constraints) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 975 | return CreateTestClients(init_constraints, nullptr, recv_constraints, |
| 976 | nullptr); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 980 | PeerConnectionFactory::Options* init_options, |
| 981 | MediaConstraintsInterface* recv_constraints, |
| 982 | PeerConnectionFactory::Options* recv_options) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 983 | initiating_client_.reset(PeerConnectionTestClient::CreateClient( |
| 984 | "Caller: ", init_constraints, init_options)); |
| 985 | receiving_client_.reset(PeerConnectionTestClient::CreateClient( |
| 986 | "Callee: ", recv_constraints, recv_options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 987 | if (!initiating_client_ || !receiving_client_) { |
| 988 | return false; |
| 989 | } |
| 990 | initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| 991 | receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| 992 | return true; |
| 993 | } |
| 994 | |
| 995 | void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, |
| 996 | const webrtc::FakeConstraints& recv_constraints) { |
| 997 | initiating_client_->SetVideoConstraints(init_constraints); |
| 998 | receiving_client_->SetVideoConstraints(recv_constraints); |
| 999 | } |
| 1000 | |
| 1001 | void EnableVideoDecoderFactory() { |
| 1002 | initiating_client_->EnableVideoDecoderFactory(); |
| 1003 | receiving_client_->EnableVideoDecoderFactory(); |
| 1004 | } |
| 1005 | |
| 1006 | // This test sets up a call between two parties. Both parties send static |
| 1007 | // frames to each other. Once the test is finished the number of sent frames |
| 1008 | // is compared to the number of received frames. |
| 1009 | void LocalP2PTest() { |
| 1010 | if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
| 1011 | initiating_client_->AddMediaStream(true, true); |
| 1012 | } |
| 1013 | initiating_client_->Negotiate(); |
deadbeef | 5def7b9 | 2015-11-20 11:43:22 -0800 | [diff] [blame] | 1014 | const int kMaxWaitForActivationMs = 5000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1015 | // Assert true is used here since next tests are guaranteed to fail and |
| 1016 | // would eat up 5 seconds. |
| 1017 | ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 1018 | VerifySessionDescriptions(); |
| 1019 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1020 | int audio_frame_count = kEndAudioFrameCount; |
| 1021 | // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
| 1022 | if (!initiating_client_->can_receive_audio() || |
| 1023 | !receiving_client_->can_receive_audio()) { |
| 1024 | audio_frame_count = -1; |
| 1025 | } |
| 1026 | int video_frame_count = kEndVideoFrameCount; |
| 1027 | if (!initiating_client_->can_receive_video() || |
| 1028 | !receiving_client_->can_receive_video()) { |
| 1029 | video_frame_count = -1; |
| 1030 | } |
| 1031 | |
| 1032 | if (audio_frame_count != -1 || video_frame_count != -1) { |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1033 | // Audio or video is expected to flow, so both clients should reach the |
| 1034 | // Connected state, and the offerer (ICE controller) should proceed to |
| 1035 | // Completed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1036 | // Note: These tests have been observed to fail under heavy load at |
| 1037 | // shorter timeouts, so they may be flaky. |
| 1038 | EXPECT_EQ_WAIT( |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1039 | webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1040 | initiating_client_->ice_connection_state(), |
| 1041 | kMaxWaitForFramesMs); |
| 1042 | EXPECT_EQ_WAIT( |
| 1043 | webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1044 | receiving_client_->ice_connection_state(), |
| 1045 | kMaxWaitForFramesMs); |
| 1046 | } |
| 1047 | |
| 1048 | if (initiating_client_->can_receive_audio() || |
| 1049 | initiating_client_->can_receive_video()) { |
| 1050 | // The initiating client can receive media, so it must produce candidates |
| 1051 | // that will serve as destinations for that media. |
| 1052 | // TODO(bemasc): Understand why the state is not already Complete here, as |
| 1053 | // seems to be the case for the receiving client. This may indicate a bug |
| 1054 | // in the ICE gathering system. |
| 1055 | EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew, |
| 1056 | initiating_client_->ice_gathering_state()); |
| 1057 | } |
| 1058 | if (receiving_client_->can_receive_audio() || |
| 1059 | receiving_client_->can_receive_video()) { |
| 1060 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 1061 | receiving_client_->ice_gathering_state(), |
| 1062 | kMaxWaitForFramesMs); |
| 1063 | } |
| 1064 | |
| 1065 | EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count), |
| 1066 | kMaxWaitForFramesMs); |
| 1067 | } |
| 1068 | |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1069 | void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
| 1070 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1071 | // times to avoid test flakiness. |
| 1072 | static const size_t kSendAttempts = 5; |
| 1073 | |
| 1074 | for (size_t i = 0; i < kSendAttempts; ++i) { |
| 1075 | dc->Send(DataBuffer(data)); |
| 1076 | } |
| 1077 | } |
| 1078 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1079 | PeerConnectionTestClient* initializing_client() { |
| 1080 | return initiating_client_.get(); |
| 1081 | } |
| 1082 | PeerConnectionTestClient* receiving_client() { |
| 1083 | return receiving_client_.get(); |
| 1084 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1085 | |
| 1086 | private: |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 1087 | rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1088 | rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
| 1089 | rtc::SocketServerScope ss_scope_; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1090 | rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; |
| 1091 | rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1092 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1093 | |
kjellander@webrtc.org | d1cfa71 | 2013-10-16 16:51:52 +0000 | [diff] [blame] | 1094 | // Disable for TSan v2, see |
| 1095 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 1096 | #if !defined(THREAD_SANITIZER) |
| 1097 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1098 | // 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] | 1099 | // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 1100 | // See issue webrtc/2378. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1101 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestDtmf) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1102 | ASSERT_TRUE(CreateTestClients()); |
| 1103 | LocalP2PTest(); |
| 1104 | VerifyDtmf(); |
| 1105 | } |
| 1106 | |
| 1107 | // This test sets up a Jsep call between two parties and test that we can get a |
| 1108 | // video aspect ratio of 16:9. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1109 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTest16To9) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1110 | ASSERT_TRUE(CreateTestClients()); |
| 1111 | FakeConstraints constraint; |
| 1112 | double requested_ratio = 640.0/360; |
| 1113 | constraint.SetMandatoryMinAspectRatio(requested_ratio); |
| 1114 | SetVideoConstraints(constraint, constraint); |
| 1115 | LocalP2PTest(); |
| 1116 | |
| 1117 | ASSERT_LE(0, initializing_client()->rendered_height()); |
| 1118 | double initiating_video_ratio = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1119 | static_cast<double>(initializing_client()->rendered_width()) / |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1120 | initializing_client()->rendered_height(); |
| 1121 | EXPECT_LE(requested_ratio, initiating_video_ratio); |
| 1122 | |
| 1123 | ASSERT_LE(0, receiving_client()->rendered_height()); |
| 1124 | double receiving_video_ratio = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1125 | static_cast<double>(receiving_client()->rendered_width()) / |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1126 | receiving_client()->rendered_height(); |
| 1127 | EXPECT_LE(requested_ratio, receiving_video_ratio); |
| 1128 | } |
| 1129 | |
| 1130 | // This test sets up a Jsep call between two parties and test that the |
| 1131 | // received video has a resolution of 1280*720. |
| 1132 | // TODO(mallinath): Enable when |
| 1133 | // http://code.google.com/p/webrtc/issues/detail?id=981 is fixed. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1134 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTest1280By720) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1135 | ASSERT_TRUE(CreateTestClients()); |
| 1136 | FakeConstraints constraint; |
| 1137 | constraint.SetMandatoryMinWidth(1280); |
| 1138 | constraint.SetMandatoryMinHeight(720); |
| 1139 | SetVideoConstraints(constraint, constraint); |
| 1140 | LocalP2PTest(); |
| 1141 | VerifyRenderedSize(1280, 720); |
| 1142 | } |
| 1143 | |
| 1144 | // This test sets up a call between two endpoints that are configured to use |
| 1145 | // DTLS key agreement. As a result, DTLS is negotiated and used for transport. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1146 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDtls) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1147 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1148 | FakeConstraints setup_constraints; |
| 1149 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1150 | true); |
| 1151 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1152 | LocalP2PTest(); |
| 1153 | VerifyRenderedSize(640, 480); |
| 1154 | } |
| 1155 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1156 | // This test sets up a audio call initially and then upgrades to audio/video, |
| 1157 | // using DTLS. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1158 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsRenegotiate) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1159 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1160 | FakeConstraints setup_constraints; |
| 1161 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1162 | true); |
| 1163 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1164 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1165 | LocalP2PTest(); |
| 1166 | receiving_client()->SetReceiveAudioVideo(true, true); |
| 1167 | receiving_client()->Negotiate(); |
| 1168 | } |
| 1169 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1170 | // This test sets up a call between two endpoints that are configured to use |
| 1171 | // DTLS key agreement. The offerer don't support SDES. As a result, DTLS is |
| 1172 | // negotiated and used for transport. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1173 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
| 1174 | MAYBE_LocalP2PTestOfferDtlsButNotSdes) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1175 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1176 | FakeConstraints setup_constraints; |
| 1177 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1178 | true); |
| 1179 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1180 | receiving_client()->RemoveSdesCryptoFromReceivedSdp(true); |
| 1181 | LocalP2PTest(); |
| 1182 | VerifyRenderedSize(640, 480); |
| 1183 | } |
| 1184 | |
| 1185 | // This test sets up a Jsep call between two parties, and the callee only |
| 1186 | // accept to receive video. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1187 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerVideo) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1188 | ASSERT_TRUE(CreateTestClients()); |
| 1189 | receiving_client()->SetReceiveAudioVideo(false, true); |
| 1190 | LocalP2PTest(); |
| 1191 | } |
| 1192 | |
| 1193 | // This test sets up a Jsep call between two parties, and the callee only |
| 1194 | // accept to receive audio. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1195 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerAudio) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1196 | ASSERT_TRUE(CreateTestClients()); |
| 1197 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1198 | LocalP2PTest(); |
| 1199 | } |
| 1200 | |
| 1201 | // This test sets up a Jsep call between two parties, and the callee reject both |
| 1202 | // audio and video. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1203 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerNone) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1204 | ASSERT_TRUE(CreateTestClients()); |
| 1205 | receiving_client()->SetReceiveAudioVideo(false, false); |
| 1206 | LocalP2PTest(); |
| 1207 | } |
| 1208 | |
| 1209 | // This test sets up an audio and video call between two parties. After the call |
| 1210 | // runs for a while (10 frames), the caller sends an update offer with video |
| 1211 | // being rejected. Once the re-negotiation is done, the video flow should stop |
| 1212 | // and the audio flow should continue. |
buildbot@webrtc.org | 688ed69 | 2014-05-14 18:26:09 +0000 | [diff] [blame] | 1213 | // Disabled due to b/14955157. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1214 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
deadbeef | cbc9507 | 2015-10-15 19:31:56 -0700 | [diff] [blame] | 1215 | DISABLED_UpdateOfferWithRejectedContent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1216 | ASSERT_TRUE(CreateTestClients()); |
| 1217 | LocalP2PTest(); |
| 1218 | TestUpdateOfferWithRejectedContent(); |
| 1219 | } |
| 1220 | |
| 1221 | // This test sets up a Jsep call between two parties. The MSID is removed from |
| 1222 | // the SDP strings from the caller. |
buildbot@webrtc.org | 688ed69 | 2014-05-14 18:26:09 +0000 | [diff] [blame] | 1223 | // Disabled due to b/14955157. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1224 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
| 1225 | DISABLED_LocalP2PTestWithoutMsid) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1226 | ASSERT_TRUE(CreateTestClients()); |
| 1227 | receiving_client()->RemoveMsidFromReceivedSdp(true); |
| 1228 | // TODO(perkj): Currently there is a bug that cause audio to stop playing if |
| 1229 | // audio and video is muxed when MSID is disabled. Remove |
| 1230 | // SetRemoveBundleFromSdp once |
| 1231 | // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed. |
| 1232 | receiving_client()->RemoveBundleFromReceivedSdp(true); |
| 1233 | LocalP2PTest(); |
| 1234 | } |
| 1235 | |
| 1236 | // This test sets up a Jsep call between two parties and the initiating peer |
| 1237 | // sends two steams. |
| 1238 | // TODO(perkj): Disabled due to |
| 1239 | // https://code.google.com/p/webrtc/issues/detail?id=1454 |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1240 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestTwoStreams) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1241 | ASSERT_TRUE(CreateTestClients()); |
| 1242 | // Set optional video constraint to max 320pixels to decrease CPU usage. |
| 1243 | FakeConstraints constraint; |
| 1244 | constraint.SetOptionalMaxWidth(320); |
| 1245 | SetVideoConstraints(constraint, constraint); |
| 1246 | initializing_client()->AddMediaStream(true, true); |
| 1247 | initializing_client()->AddMediaStream(false, true); |
| 1248 | ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams()); |
| 1249 | LocalP2PTest(); |
| 1250 | EXPECT_EQ(2u, receiving_client()->number_of_remote_streams()); |
| 1251 | } |
| 1252 | |
| 1253 | // Test that we can receive the audio output level from a remote audio track. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1254 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, MAYBE_GetAudioOutputLevelStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1255 | ASSERT_TRUE(CreateTestClients()); |
| 1256 | LocalP2PTest(); |
| 1257 | |
| 1258 | StreamCollectionInterface* remote_streams = |
| 1259 | initializing_client()->remote_streams(); |
| 1260 | ASSERT_GT(remote_streams->count(), 0u); |
| 1261 | ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1262 | MediaStreamTrackInterface* remote_audio_track = |
| 1263 | remote_streams->at(0)->GetAudioTracks()[0]; |
| 1264 | |
| 1265 | // Get the audio output level stats. Note that the level is not available |
| 1266 | // until a RTCP packet has been received. |
| 1267 | EXPECT_TRUE_WAIT( |
| 1268 | initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0, |
| 1269 | kMaxWaitForStatsMs); |
| 1270 | } |
| 1271 | |
| 1272 | // Test that an audio input level is reported. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1273 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, MAYBE_GetAudioInputLevelStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1274 | ASSERT_TRUE(CreateTestClients()); |
| 1275 | LocalP2PTest(); |
| 1276 | |
| 1277 | // Get the audio input level stats. The level should be available very |
| 1278 | // soon after the test starts. |
| 1279 | EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0, |
| 1280 | kMaxWaitForStatsMs); |
| 1281 | } |
| 1282 | |
| 1283 | // Test that we can get incoming byte counts from both audio and video tracks. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1284 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, MAYBE_GetBytesReceivedStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1285 | ASSERT_TRUE(CreateTestClients()); |
| 1286 | LocalP2PTest(); |
| 1287 | |
| 1288 | StreamCollectionInterface* remote_streams = |
| 1289 | initializing_client()->remote_streams(); |
| 1290 | ASSERT_GT(remote_streams->count(), 0u); |
| 1291 | ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1292 | MediaStreamTrackInterface* remote_audio_track = |
| 1293 | remote_streams->at(0)->GetAudioTracks()[0]; |
| 1294 | EXPECT_TRUE_WAIT( |
| 1295 | initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0, |
| 1296 | kMaxWaitForStatsMs); |
| 1297 | |
| 1298 | MediaStreamTrackInterface* remote_video_track = |
| 1299 | remote_streams->at(0)->GetVideoTracks()[0]; |
| 1300 | EXPECT_TRUE_WAIT( |
| 1301 | initializing_client()->GetBytesReceivedStats(remote_video_track) > 0, |
| 1302 | kMaxWaitForStatsMs); |
| 1303 | } |
| 1304 | |
| 1305 | // Test that we can get outgoing byte counts from both audio and video tracks. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1306 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, MAYBE_GetBytesSentStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1307 | ASSERT_TRUE(CreateTestClients()); |
| 1308 | LocalP2PTest(); |
| 1309 | |
| 1310 | StreamCollectionInterface* local_streams = |
| 1311 | initializing_client()->local_streams(); |
| 1312 | ASSERT_GT(local_streams->count(), 0u); |
| 1313 | ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1314 | MediaStreamTrackInterface* local_audio_track = |
| 1315 | local_streams->at(0)->GetAudioTracks()[0]; |
| 1316 | EXPECT_TRUE_WAIT( |
| 1317 | initializing_client()->GetBytesSentStats(local_audio_track) > 0, |
| 1318 | kMaxWaitForStatsMs); |
| 1319 | |
| 1320 | MediaStreamTrackInterface* local_video_track = |
| 1321 | local_streams->at(0)->GetVideoTracks()[0]; |
| 1322 | EXPECT_TRUE_WAIT( |
| 1323 | initializing_client()->GetBytesSentStats(local_video_track) > 0, |
| 1324 | kMaxWaitForStatsMs); |
| 1325 | } |
| 1326 | |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1327 | // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1328 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, GetDtls12None) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1329 | PeerConnectionFactory::Options init_options; |
| 1330 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1331 | PeerConnectionFactory::Options recv_options; |
| 1332 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1333 | ASSERT_TRUE( |
| 1334 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1335 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1336 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1337 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 1338 | LocalP2PTest(); |
| 1339 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1340 | EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1341 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1342 | rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)), |
| 1343 | initializing_client()->GetDtlsCipherStats(), |
| 1344 | kMaxWaitForStatsMs); |
| 1345 | EXPECT_EQ(1, init_observer->GetEnumCounter( |
| 1346 | webrtc::kEnumCounterAudioSslCipher, |
| 1347 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1348 | rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1349 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1350 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1351 | initializing_client()->GetSrtpCipherStats(), |
| 1352 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1353 | EXPECT_EQ(1, |
| 1354 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1355 | kDefaultSrtpCryptoSuite)); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | // Test that DTLS 1.2 is used if both ends support it. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1359 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, MAYBE_GetDtls12Both) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1360 | PeerConnectionFactory::Options init_options; |
| 1361 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1362 | PeerConnectionFactory::Options recv_options; |
| 1363 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1364 | ASSERT_TRUE( |
| 1365 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1366 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1367 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1368 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1369 | LocalP2PTest(); |
| 1370 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1371 | EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1372 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1373 | rtc::SSL_PROTOCOL_DTLS_12, rtc::KT_DEFAULT)), |
| 1374 | initializing_client()->GetDtlsCipherStats(), |
| 1375 | kMaxWaitForStatsMs); |
| 1376 | EXPECT_EQ(1, init_observer->GetEnumCounter( |
| 1377 | webrtc::kEnumCounterAudioSslCipher, |
| 1378 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1379 | rtc::SSL_PROTOCOL_DTLS_12, rtc::KT_DEFAULT))); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1380 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1381 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1382 | initializing_client()->GetSrtpCipherStats(), |
| 1383 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1384 | EXPECT_EQ(1, |
| 1385 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1386 | kDefaultSrtpCryptoSuite)); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the |
| 1390 | // received supports 1.0. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1391 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, GetDtls12Init) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1392 | PeerConnectionFactory::Options init_options; |
| 1393 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1394 | PeerConnectionFactory::Options recv_options; |
| 1395 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1396 | ASSERT_TRUE( |
| 1397 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1398 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1399 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1400 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1401 | LocalP2PTest(); |
| 1402 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1403 | EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1404 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1405 | rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)), |
| 1406 | initializing_client()->GetDtlsCipherStats(), |
| 1407 | kMaxWaitForStatsMs); |
| 1408 | EXPECT_EQ(1, init_observer->GetEnumCounter( |
| 1409 | webrtc::kEnumCounterAudioSslCipher, |
| 1410 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1411 | rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1412 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1413 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1414 | initializing_client()->GetSrtpCipherStats(), |
| 1415 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1416 | EXPECT_EQ(1, |
| 1417 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1418 | kDefaultSrtpCryptoSuite)); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the |
| 1422 | // received supports 1.2. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1423 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, GetDtls12Recv) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1424 | PeerConnectionFactory::Options init_options; |
| 1425 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1426 | PeerConnectionFactory::Options recv_options; |
| 1427 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1428 | ASSERT_TRUE( |
| 1429 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1430 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1431 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1432 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1433 | LocalP2PTest(); |
| 1434 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1435 | EXPECT_EQ_WAIT(rtc::SSLStreamAdapter::SslCipherSuiteToName( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1436 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1437 | rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)), |
| 1438 | initializing_client()->GetDtlsCipherStats(), |
| 1439 | kMaxWaitForStatsMs); |
| 1440 | EXPECT_EQ(1, init_observer->GetEnumCounter( |
| 1441 | webrtc::kEnumCounterAudioSslCipher, |
| 1442 | rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1443 | rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 1444 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1445 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1446 | initializing_client()->GetSrtpCipherStats(), |
| 1447 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1448 | EXPECT_EQ(1, |
| 1449 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1450 | kDefaultSrtpCryptoSuite)); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1453 | // This test sets up a call between two parties with audio, video and data. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1454 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1455 | FakeConstraints setup_constraints; |
| 1456 | setup_constraints.SetAllowRtpDataChannels(); |
| 1457 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1458 | initializing_client()->CreateDataChannel(); |
| 1459 | LocalP2PTest(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1460 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1461 | ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1462 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1463 | kMaxWaitMs); |
| 1464 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), |
| 1465 | kMaxWaitMs); |
| 1466 | |
| 1467 | std::string data = "hello world"; |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1468 | |
| 1469 | SendRtpData(initializing_client()->data_channel(), data); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1470 | EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), |
| 1471 | kMaxWaitMs); |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1472 | |
| 1473 | SendRtpData(receiving_client()->data_channel(), data); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1474 | EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), |
| 1475 | kMaxWaitMs); |
| 1476 | |
| 1477 | receiving_client()->data_channel()->Close(); |
| 1478 | // Send new offer and answer. |
| 1479 | receiving_client()->Negotiate(); |
| 1480 | EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); |
| 1481 | EXPECT_FALSE(receiving_client()->data_observer()->IsOpen()); |
| 1482 | } |
| 1483 | |
| 1484 | // This test sets up a call between two parties and creates a data channel. |
| 1485 | // The test tests that received data is buffered unless an observer has been |
| 1486 | // registered. |
| 1487 | // Rtp data channels can receive data before the underlying |
| 1488 | // transport has detected that a channel is writable and thus data can be |
| 1489 | // received before the data channel state changes to open. That is hard to test |
| 1490 | // but the same buffering is used in that case. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1491 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, RegisterDataChannelObserver) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1492 | FakeConstraints setup_constraints; |
| 1493 | setup_constraints.SetAllowRtpDataChannels(); |
| 1494 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1495 | initializing_client()->CreateDataChannel(); |
| 1496 | initializing_client()->Negotiate(); |
| 1497 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1498 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1499 | ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1500 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1501 | kMaxWaitMs); |
| 1502 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, |
| 1503 | receiving_client()->data_channel()->state(), kMaxWaitMs); |
| 1504 | |
| 1505 | // Unregister the existing observer. |
| 1506 | receiving_client()->data_channel()->UnregisterObserver(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1507 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1508 | std::string data = "hello world"; |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1509 | SendRtpData(initializing_client()->data_channel(), data); |
| 1510 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1511 | // Wait a while to allow the sent data to arrive before an observer is |
| 1512 | // registered.. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1513 | rtc::Thread::Current()->ProcessMessages(100); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1514 | |
| 1515 | MockDataChannelObserver new_observer(receiving_client()->data_channel()); |
| 1516 | EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs); |
| 1517 | } |
| 1518 | |
| 1519 | // This test sets up a call between two parties with audio, video and but only |
| 1520 | // the initiating client support data. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1521 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
| 1522 | LocalP2PTestReceiverDoesntSupportData) { |
buildbot@webrtc.org | 61c1b8e | 2014-04-09 06:06:38 +0000 | [diff] [blame] | 1523 | FakeConstraints setup_constraints_1; |
| 1524 | setup_constraints_1.SetAllowRtpDataChannels(); |
| 1525 | // Must disable DTLS to make negotiation succeed. |
| 1526 | setup_constraints_1.SetMandatory( |
| 1527 | MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 1528 | FakeConstraints setup_constraints_2; |
| 1529 | setup_constraints_2.SetMandatory( |
| 1530 | MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 1531 | ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1532 | initializing_client()->CreateDataChannel(); |
| 1533 | LocalP2PTest(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1534 | EXPECT_TRUE(initializing_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1535 | EXPECT_FALSE(receiving_client()->data_channel()); |
| 1536 | EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); |
| 1537 | } |
| 1538 | |
| 1539 | // This test sets up a call between two parties with audio, video. When audio |
| 1540 | // and video is setup and flowing and data channel is negotiated. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1541 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
| 1542 | AddDataChannelAfterRenegotiation) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1543 | FakeConstraints setup_constraints; |
| 1544 | setup_constraints.SetAllowRtpDataChannels(); |
| 1545 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1546 | LocalP2PTest(); |
| 1547 | initializing_client()->CreateDataChannel(); |
| 1548 | // Send new offer and answer. |
| 1549 | initializing_client()->Negotiate(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1550 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1551 | ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1552 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1553 | kMaxWaitMs); |
| 1554 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), |
| 1555 | kMaxWaitMs); |
| 1556 | } |
| 1557 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1558 | // This test sets up a Jsep call with SCTP DataChannel and verifies the |
| 1559 | // negotiation is completed without error. |
| 1560 | #ifdef HAVE_SCTP |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1561 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, CreateOfferWithSctpDataChannel) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1562 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1563 | FakeConstraints constraints; |
| 1564 | constraints.SetMandatory( |
| 1565 | MediaConstraintsInterface::kEnableDtlsSrtp, true); |
| 1566 | ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); |
| 1567 | initializing_client()->CreateDataChannel(); |
| 1568 | initializing_client()->Negotiate(false, false); |
| 1569 | } |
| 1570 | #endif |
| 1571 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1572 | // This test sets up a call between two parties with audio, and video. |
| 1573 | // During the call, the initializing side restart ice and the test verifies that |
| 1574 | // new ice candidates are generated and audio and video still can flow. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1575 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, MAYBE_IceRestart) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1576 | ASSERT_TRUE(CreateTestClients()); |
| 1577 | |
| 1578 | // Negotiate and wait for ice completion and make sure audio and video plays. |
| 1579 | LocalP2PTest(); |
| 1580 | |
| 1581 | // Create a SDP string of the first audio candidate for both clients. |
| 1582 | const webrtc::IceCandidateCollection* audio_candidates_initiator = |
| 1583 | initializing_client()->pc()->local_description()->candidates(0); |
| 1584 | const webrtc::IceCandidateCollection* audio_candidates_receiver = |
| 1585 | receiving_client()->pc()->local_description()->candidates(0); |
| 1586 | ASSERT_GT(audio_candidates_initiator->count(), 0u); |
| 1587 | ASSERT_GT(audio_candidates_receiver->count(), 0u); |
| 1588 | std::string initiator_candidate; |
| 1589 | EXPECT_TRUE( |
| 1590 | audio_candidates_initiator->at(0)->ToString(&initiator_candidate)); |
| 1591 | std::string receiver_candidate; |
| 1592 | EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate)); |
| 1593 | |
| 1594 | // Restart ice on the initializing client. |
| 1595 | receiving_client()->SetExpectIceRestart(true); |
| 1596 | initializing_client()->IceRestart(); |
| 1597 | |
| 1598 | // Negotiate and wait for ice completion again and make sure audio and video |
| 1599 | // plays. |
| 1600 | LocalP2PTest(); |
| 1601 | |
| 1602 | // Create a SDP string of the first audio candidate for both clients again. |
| 1603 | const webrtc::IceCandidateCollection* audio_candidates_initiator_restart = |
| 1604 | initializing_client()->pc()->local_description()->candidates(0); |
| 1605 | const webrtc::IceCandidateCollection* audio_candidates_reciever_restart = |
| 1606 | receiving_client()->pc()->local_description()->candidates(0); |
| 1607 | ASSERT_GT(audio_candidates_initiator_restart->count(), 0u); |
| 1608 | ASSERT_GT(audio_candidates_reciever_restart->count(), 0u); |
| 1609 | std::string initiator_candidate_restart; |
| 1610 | EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString( |
| 1611 | &initiator_candidate_restart)); |
| 1612 | std::string receiver_candidate_restart; |
| 1613 | EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString( |
| 1614 | &receiver_candidate_restart)); |
| 1615 | |
| 1616 | // Verify that the first candidates in the local session descriptions has |
| 1617 | // changed. |
| 1618 | EXPECT_NE(initiator_candidate, initiator_candidate_restart); |
| 1619 | EXPECT_NE(receiver_candidate, receiver_candidate_restart); |
| 1620 | } |
| 1621 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1622 | // This test sets up a call between two parties with audio, and video. |
| 1623 | // It then renegotiates setting the video m-line to "port 0", then later |
| 1624 | // renegotiates again, enabling video. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1625 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, LocalP2PTestVideoDisableEnable) { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1626 | ASSERT_TRUE(CreateTestClients()); |
| 1627 | |
| 1628 | // Do initial negotiation. Will result in video and audio sendonly m-lines. |
| 1629 | receiving_client()->set_auto_add_stream(false); |
| 1630 | initializing_client()->AddMediaStream(true, true); |
| 1631 | initializing_client()->Negotiate(); |
| 1632 | |
| 1633 | // Negotiate again, disabling the video m-line (receiving client will |
| 1634 | // set port to 0 due to mandatory "OfferToReceiveVideo: false" constraint). |
| 1635 | receiving_client()->SetReceiveVideo(false); |
| 1636 | initializing_client()->Negotiate(); |
| 1637 | |
| 1638 | // Enable video and do negotiation again, making sure video is received |
| 1639 | // end-to-end. |
| 1640 | receiving_client()->SetReceiveVideo(true); |
| 1641 | receiving_client()->AddMediaStream(true, true); |
| 1642 | LocalP2PTest(); |
| 1643 | } |
| 1644 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1645 | // This test sets up a Jsep call between two parties with external |
| 1646 | // VideoDecoderFactory. |
stefan@webrtc.org | da79008 | 2013-09-17 13:11:38 +0000 | [diff] [blame] | 1647 | // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 1648 | // See issue webrtc/2378. |
ivoc | 191c1f9 | 2015-11-19 11:12:06 -0800 | [diff] [blame] | 1649 | TEST_F(MAYBE_JsepPeerConnectionP2PTestClient, |
deadbeef | cbc9507 | 2015-10-15 19:31:56 -0700 | [diff] [blame] | 1650 | DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1651 | ASSERT_TRUE(CreateTestClients()); |
| 1652 | EnableVideoDecoderFactory(); |
| 1653 | LocalP2PTest(); |
| 1654 | } |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1655 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 1656 | class IceServerParsingTest : public testing::Test { |
| 1657 | public: |
| 1658 | // Convenience for parsing a single URL. |
| 1659 | bool ParseUrl(const std::string& url) { |
| 1660 | return ParseUrl(url, std::string(), std::string()); |
| 1661 | } |
| 1662 | |
| 1663 | bool ParseUrl(const std::string& url, |
| 1664 | const std::string& username, |
| 1665 | const std::string& password) { |
| 1666 | PeerConnectionInterface::IceServers servers; |
| 1667 | PeerConnectionInterface::IceServer server; |
| 1668 | server.urls.push_back(url); |
| 1669 | server.username = username; |
| 1670 | server.password = password; |
| 1671 | servers.push_back(server); |
| 1672 | return webrtc::ParseIceServers(servers, &stun_configurations_, |
| 1673 | &turn_configurations_); |
| 1674 | } |
| 1675 | |
| 1676 | protected: |
| 1677 | webrtc::StunConfigurations stun_configurations_; |
| 1678 | webrtc::TurnConfigurations turn_configurations_; |
| 1679 | }; |
| 1680 | |
| 1681 | // Make sure all STUN/TURN prefixes are parsed correctly. |
| 1682 | TEST_F(IceServerParsingTest, ParseStunPrefixes) { |
| 1683 | EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1684 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1685 | EXPECT_EQ(0U, turn_configurations_.size()); |
| 1686 | stun_configurations_.clear(); |
| 1687 | |
| 1688 | EXPECT_TRUE(ParseUrl("stuns:hostname")); |
| 1689 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1690 | EXPECT_EQ(0U, turn_configurations_.size()); |
| 1691 | stun_configurations_.clear(); |
| 1692 | |
| 1693 | EXPECT_TRUE(ParseUrl("turn:hostname")); |
| 1694 | EXPECT_EQ(0U, stun_configurations_.size()); |
| 1695 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1696 | EXPECT_FALSE(turn_configurations_[0].secure); |
| 1697 | turn_configurations_.clear(); |
| 1698 | |
| 1699 | EXPECT_TRUE(ParseUrl("turns:hostname")); |
| 1700 | EXPECT_EQ(0U, stun_configurations_.size()); |
| 1701 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1702 | EXPECT_TRUE(turn_configurations_[0].secure); |
| 1703 | turn_configurations_.clear(); |
| 1704 | |
| 1705 | // invalid prefixes |
| 1706 | EXPECT_FALSE(ParseUrl("stunn:hostname")); |
| 1707 | EXPECT_FALSE(ParseUrl(":hostname")); |
| 1708 | EXPECT_FALSE(ParseUrl(":")); |
| 1709 | EXPECT_FALSE(ParseUrl("")); |
| 1710 | } |
| 1711 | |
| 1712 | TEST_F(IceServerParsingTest, VerifyDefaults) { |
| 1713 | // TURNS defaults |
| 1714 | EXPECT_TRUE(ParseUrl("turns:hostname")); |
| 1715 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1716 | EXPECT_EQ(5349, turn_configurations_[0].server.port()); |
| 1717 | EXPECT_EQ("tcp", turn_configurations_[0].transport_type); |
| 1718 | turn_configurations_.clear(); |
| 1719 | |
| 1720 | // TURN defaults |
| 1721 | EXPECT_TRUE(ParseUrl("turn:hostname")); |
| 1722 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1723 | EXPECT_EQ(3478, turn_configurations_[0].server.port()); |
| 1724 | EXPECT_EQ("udp", turn_configurations_[0].transport_type); |
| 1725 | turn_configurations_.clear(); |
| 1726 | |
| 1727 | // STUN defaults |
| 1728 | EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1729 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1730 | EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1731 | stun_configurations_.clear(); |
| 1732 | } |
| 1733 | |
| 1734 | // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port |
| 1735 | // can be parsed correctly. |
| 1736 | TEST_F(IceServerParsingTest, ParseHostnameAndPort) { |
| 1737 | EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); |
| 1738 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1739 | EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); |
| 1740 | EXPECT_EQ(1234, stun_configurations_[0].server.port()); |
| 1741 | stun_configurations_.clear(); |
| 1742 | |
| 1743 | EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); |
| 1744 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1745 | EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); |
| 1746 | EXPECT_EQ(4321, stun_configurations_[0].server.port()); |
| 1747 | stun_configurations_.clear(); |
| 1748 | |
| 1749 | EXPECT_TRUE(ParseUrl("stun:hostname:9999")); |
| 1750 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1751 | EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); |
| 1752 | EXPECT_EQ(9999, stun_configurations_[0].server.port()); |
| 1753 | stun_configurations_.clear(); |
| 1754 | |
| 1755 | EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); |
| 1756 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1757 | EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); |
| 1758 | EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1759 | stun_configurations_.clear(); |
| 1760 | |
| 1761 | EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); |
| 1762 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1763 | EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); |
| 1764 | EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1765 | stun_configurations_.clear(); |
| 1766 | |
| 1767 | EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1768 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1769 | EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); |
| 1770 | EXPECT_EQ(3478, stun_configurations_[0].server.port()); |
| 1771 | stun_configurations_.clear(); |
| 1772 | |
| 1773 | // Try some invalid hostname:port strings. |
| 1774 | EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); |
| 1775 | EXPECT_FALSE(ParseUrl("stun:hostname:-1")); |
| 1776 | EXPECT_FALSE(ParseUrl("stun:hostname:")); |
| 1777 | EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); |
| 1778 | EXPECT_FALSE(ParseUrl("stun::5555")); |
| 1779 | EXPECT_FALSE(ParseUrl("stun:")); |
| 1780 | } |
| 1781 | |
| 1782 | // Test parsing the "?transport=xxx" part of the URL. |
| 1783 | TEST_F(IceServerParsingTest, ParseTransport) { |
| 1784 | EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); |
| 1785 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1786 | EXPECT_EQ("tcp", turn_configurations_[0].transport_type); |
| 1787 | turn_configurations_.clear(); |
| 1788 | |
| 1789 | EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); |
| 1790 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1791 | EXPECT_EQ("udp", turn_configurations_[0].transport_type); |
| 1792 | turn_configurations_.clear(); |
| 1793 | |
| 1794 | EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); |
| 1795 | } |
| 1796 | |
| 1797 | // Test parsing ICE username contained in URL. |
| 1798 | TEST_F(IceServerParsingTest, ParseUsername) { |
| 1799 | EXPECT_TRUE(ParseUrl("turn:user@hostname")); |
| 1800 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1801 | EXPECT_EQ("user", turn_configurations_[0].username); |
| 1802 | turn_configurations_.clear(); |
| 1803 | |
| 1804 | EXPECT_FALSE(ParseUrl("turn:@hostname")); |
| 1805 | EXPECT_FALSE(ParseUrl("turn:username@")); |
| 1806 | EXPECT_FALSE(ParseUrl("turn:@")); |
| 1807 | EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); |
| 1808 | } |
| 1809 | |
| 1810 | // Test that username and password from IceServer is copied into the resulting |
| 1811 | // TurnConfiguration. |
| 1812 | TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { |
| 1813 | EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); |
| 1814 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1815 | EXPECT_EQ("username", turn_configurations_[0].username); |
| 1816 | EXPECT_EQ("password", turn_configurations_[0].password); |
| 1817 | } |
| 1818 | |
| 1819 | // Ensure that if a server has multiple URLs, each one is parsed. |
| 1820 | TEST_F(IceServerParsingTest, ParseMultipleUrls) { |
| 1821 | PeerConnectionInterface::IceServers servers; |
| 1822 | PeerConnectionInterface::IceServer server; |
| 1823 | server.urls.push_back("stun:hostname"); |
| 1824 | server.urls.push_back("turn:hostname"); |
| 1825 | servers.push_back(server); |
| 1826 | EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, |
| 1827 | &turn_configurations_)); |
| 1828 | EXPECT_EQ(1U, stun_configurations_.size()); |
| 1829 | EXPECT_EQ(1U, turn_configurations_.size()); |
| 1830 | } |
| 1831 | |
kjellander@webrtc.org | d1cfa71 | 2013-10-16 16:51:52 +0000 | [diff] [blame] | 1832 | #endif // if !defined(THREAD_SANITIZER) |