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