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