henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | #include <algorithm> |
| 14 | #include <list> |
| 15 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 16 | #include <memory> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 17 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 20 | #include "webrtc/api/dtmfsender.h" |
| 21 | #include "webrtc/api/fakemetricsobserver.h" |
| 22 | #include "webrtc/api/localaudiosource.h" |
| 23 | #include "webrtc/api/mediastreaminterface.h" |
| 24 | #include "webrtc/api/peerconnection.h" |
| 25 | #include "webrtc/api/peerconnectionfactory.h" |
| 26 | #include "webrtc/api/peerconnectioninterface.h" |
| 27 | #include "webrtc/api/test/fakeaudiocapturemodule.h" |
| 28 | #include "webrtc/api/test/fakeconstraints.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 29 | #include "webrtc/api/test/fakeperiodicvideocapturer.h" |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 30 | #include "webrtc/api/test/fakertccertificategenerator.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 31 | #include "webrtc/api/test/fakevideotrackrenderer.h" |
| 32 | #include "webrtc/api/test/mockpeerconnectionobservers.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 33 | #include "webrtc/base/gunit.h" |
Taylor Brandstetter | 9b5306c | 2016-08-18 11:40:37 -0700 | [diff] [blame^] | 34 | #include "webrtc/base/helpers.h" |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 35 | #include "webrtc/base/physicalsocketserver.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 36 | #include "webrtc/base/ssladapter.h" |
| 37 | #include "webrtc/base/sslstreamadapter.h" |
| 38 | #include "webrtc/base/thread.h" |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 39 | #include "webrtc/base/virtualsocketserver.h" |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 40 | #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 41 | #include "webrtc/p2p/base/fakeportallocator.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 42 | #include "webrtc/p2p/base/p2pconstants.h" |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 43 | #include "webrtc/p2p/base/sessiondescription.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 44 | #include "webrtc/pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | |
| 46 | #define MAYBE_SKIP_TEST(feature) \ |
| 47 | if (!(feature())) { \ |
| 48 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 49 | return; \ |
| 50 | } |
| 51 | |
| 52 | using cricket::ContentInfo; |
| 53 | using cricket::FakeWebRtcVideoDecoder; |
| 54 | using cricket::FakeWebRtcVideoDecoderFactory; |
| 55 | using cricket::FakeWebRtcVideoEncoder; |
| 56 | using cricket::FakeWebRtcVideoEncoderFactory; |
| 57 | using cricket::MediaContentDescription; |
| 58 | using webrtc::DataBuffer; |
| 59 | using webrtc::DataChannelInterface; |
| 60 | using webrtc::DtmfSender; |
| 61 | using webrtc::DtmfSenderInterface; |
| 62 | using webrtc::DtmfSenderObserverInterface; |
| 63 | using webrtc::FakeConstraints; |
| 64 | using webrtc::MediaConstraintsInterface; |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 65 | using webrtc::MediaStreamInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | using webrtc::MediaStreamTrackInterface; |
| 67 | using webrtc::MockCreateSessionDescriptionObserver; |
| 68 | using webrtc::MockDataChannelObserver; |
| 69 | using webrtc::MockSetSessionDescriptionObserver; |
| 70 | using webrtc::MockStatsObserver; |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 71 | using webrtc::ObserverInterface; |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 72 | using webrtc::PeerConnectionInterface; |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 73 | using webrtc::PeerConnectionFactory; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | using webrtc::SessionDescriptionInterface; |
| 75 | using webrtc::StreamCollectionInterface; |
| 76 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 77 | namespace { |
| 78 | |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 79 | static const int kMaxWaitMs = 10000; |
pbos@webrtc.org | 044bdac | 2014-06-03 09:40:01 +0000 | [diff] [blame] | 80 | // Disable for TSan v2, see |
| 81 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 82 | // This declaration is also #ifdef'd as it causes uninitialized-variable |
| 83 | // warnings. |
| 84 | #if !defined(THREAD_SANITIZER) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | static const int kMaxWaitForStatsMs = 3000; |
pbos@webrtc.org | 044bdac | 2014-06-03 09:40:01 +0000 | [diff] [blame] | 86 | #endif |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 87 | static const int kMaxWaitForActivationMs = 5000; |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 88 | static const int kMaxWaitForFramesMs = 10000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | static const int kEndAudioFrameCount = 3; |
| 90 | static const int kEndVideoFrameCount = 3; |
| 91 | |
| 92 | static const char kStreamLabelBase[] = "stream_label"; |
| 93 | static const char kVideoTrackLabelBase[] = "video_track"; |
| 94 | static const char kAudioTrackLabelBase[] = "audio_track"; |
| 95 | static const char kDataChannelLabel[] = "data_channel"; |
| 96 | |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 97 | // Disable for TSan v2, see |
| 98 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 99 | // This declaration is also #ifdef'd as it causes unused-variable errors. |
| 100 | #if !defined(THREAD_SANITIZER) |
| 101 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 102 | // default changes. |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 103 | static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 104 | static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | static void RemoveLinesFromSdp(const std::string& line_start, |
| 108 | std::string* sdp) { |
| 109 | const char kSdpLineEnd[] = "\r\n"; |
| 110 | size_t ssrc_pos = 0; |
| 111 | while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != |
| 112 | std::string::npos) { |
| 113 | size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); |
| 114 | sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); |
| 115 | } |
| 116 | } |
| 117 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 118 | bool StreamsHaveAudioTrack(StreamCollectionInterface* streams) { |
| 119 | for (size_t idx = 0; idx < streams->count(); idx++) { |
| 120 | auto stream = streams->at(idx); |
| 121 | if (stream->GetAudioTracks().size() > 0) { |
| 122 | return true; |
| 123 | } |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | bool StreamsHaveVideoTrack(StreamCollectionInterface* streams) { |
| 129 | for (size_t idx = 0; idx < streams->count(); idx++) { |
| 130 | auto stream = streams->at(idx); |
| 131 | if (stream->GetVideoTracks().size() > 0) { |
| 132 | return true; |
| 133 | } |
| 134 | } |
| 135 | return false; |
| 136 | } |
| 137 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | class SignalingMessageReceiver { |
| 139 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | virtual void ReceiveSdpMessage(const std::string& type, |
| 141 | std::string& msg) = 0; |
| 142 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 143 | int sdp_mline_index, |
| 144 | const std::string& msg) = 0; |
| 145 | |
| 146 | protected: |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 147 | SignalingMessageReceiver() {} |
| 148 | virtual ~SignalingMessageReceiver() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 151 | class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { |
| 152 | public: |
| 153 | MockRtpReceiverObserver(cricket::MediaType media_type) |
| 154 | : expected_media_type_(media_type) {} |
| 155 | |
| 156 | void OnFirstPacketReceived(cricket::MediaType media_type) override { |
| 157 | ASSERT_EQ(expected_media_type_, media_type); |
| 158 | first_packet_received_ = true; |
| 159 | } |
| 160 | |
| 161 | bool first_packet_received() { return first_packet_received_; } |
| 162 | |
| 163 | virtual ~MockRtpReceiverObserver() {} |
| 164 | |
| 165 | private: |
| 166 | bool first_packet_received_ = false; |
| 167 | cricket::MediaType expected_media_type_; |
| 168 | }; |
| 169 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 170 | class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 171 | public SignalingMessageReceiver, |
| 172 | public ObserverInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | public: |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 174 | static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( |
Guo-wei Shieh | 9c38c2d | 2015-12-05 09:46:07 -0800 | [diff] [blame] | 175 | const std::string& id, |
| 176 | const MediaConstraintsInterface* constraints, |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 177 | const PeerConnectionFactory::Options* options, |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 178 | const PeerConnectionInterface::RTCConfiguration& config, |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 179 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 180 | bool prefer_constraint_apis, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 181 | rtc::Thread* network_thread, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 182 | rtc::Thread* worker_thread) { |
Guo-wei Shieh | 86aaa4b | 2015-12-05 09:55:44 -0800 | [diff] [blame] | 183 | PeerConnectionTestClient* client(new PeerConnectionTestClient(id)); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 184 | if (!client->Init(constraints, options, config, std::move(cert_generator), |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 185 | prefer_constraint_apis, network_thread, worker_thread)) { |
Guo-wei Shieh | 86aaa4b | 2015-12-05 09:55:44 -0800 | [diff] [blame] | 186 | delete client; |
| 187 | return nullptr; |
| 188 | } |
| 189 | return client; |
Guo-wei Shieh | 9c38c2d | 2015-12-05 09:46:07 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 192 | static PeerConnectionTestClient* CreateClient( |
| 193 | const std::string& id, |
| 194 | const MediaConstraintsInterface* constraints, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 195 | const PeerConnectionFactory::Options* options, |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 196 | const PeerConnectionInterface::RTCConfiguration& config, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 197 | rtc::Thread* network_thread, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 198 | rtc::Thread* worker_thread) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 199 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 200 | rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
| 201 | new FakeRTCCertificateGenerator() : nullptr); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 202 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 203 | return CreateClientWithDtlsIdentityStore(id, constraints, options, config, |
| 204 | std::move(cert_generator), true, |
| 205 | network_thread, worker_thread); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static PeerConnectionTestClient* CreateClientPreferNoConstraints( |
| 209 | const std::string& id, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 210 | const PeerConnectionFactory::Options* options, |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 211 | const PeerConnectionInterface::RTCConfiguration& config, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 212 | rtc::Thread* network_thread, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 213 | rtc::Thread* worker_thread) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 214 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 215 | rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
| 216 | new FakeRTCCertificateGenerator() : nullptr); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 217 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 218 | return CreateClientWithDtlsIdentityStore(id, nullptr, options, config, |
| 219 | std::move(cert_generator), false, |
| 220 | network_thread, worker_thread); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 221 | } |
| 222 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 223 | ~PeerConnectionTestClient() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 224 | } |
| 225 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 226 | void Negotiate() { Negotiate(true, true); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 228 | void Negotiate(bool audio, bool video) { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 229 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 230 | ASSERT_TRUE(DoCreateOffer(&offer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 231 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 232 | if (offer->description()->GetContentByName("audio")) { |
| 233 | offer->description()->GetContentByName("audio")->rejected = !audio; |
| 234 | } |
| 235 | if (offer->description()->GetContentByName("video")) { |
| 236 | offer->description()->GetContentByName("video")->rejected = !video; |
| 237 | } |
| 238 | |
| 239 | std::string sdp; |
| 240 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 241 | EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 242 | signaling_message_receiver_->ReceiveSdpMessage( |
| 243 | webrtc::SessionDescriptionInterface::kOffer, sdp); |
| 244 | } |
| 245 | |
| 246 | // SignalingMessageReceiver callback. |
| 247 | void ReceiveSdpMessage(const std::string& type, std::string& msg) override { |
| 248 | FilterIncomingSdpMessage(&msg); |
| 249 | if (type == webrtc::SessionDescriptionInterface::kOffer) { |
| 250 | HandleIncomingOffer(msg); |
| 251 | } else { |
| 252 | HandleIncomingAnswer(msg); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // SignalingMessageReceiver callback. |
| 257 | void ReceiveIceMessage(const std::string& sdp_mid, |
| 258 | int sdp_mline_index, |
| 259 | const std::string& msg) override { |
| 260 | LOG(INFO) << id_ << "ReceiveIceMessage"; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 261 | std::unique_ptr<webrtc::IceCandidateInterface> candidate( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 262 | webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr)); |
| 263 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 264 | } |
| 265 | |
| 266 | // PeerConnectionObserver callbacks. |
| 267 | void OnSignalingChange( |
| 268 | webrtc::PeerConnectionInterface::SignalingState new_state) override { |
| 269 | EXPECT_EQ(pc()->signaling_state(), new_state); |
| 270 | } |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 271 | void OnAddStream( |
| 272 | rtc::scoped_refptr<MediaStreamInterface> media_stream) override { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 273 | media_stream->RegisterObserver(this); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 274 | for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) { |
| 275 | const std::string id = media_stream->GetVideoTracks()[i]->id(); |
| 276 | ASSERT_TRUE(fake_video_renderers_.find(id) == |
| 277 | fake_video_renderers_.end()); |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 278 | fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer( |
| 279 | media_stream->GetVideoTracks()[i])); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 282 | void OnRemoveStream( |
| 283 | rtc::scoped_refptr<MediaStreamInterface> media_stream) override {} |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 284 | void OnRenegotiationNeeded() override {} |
| 285 | void OnIceConnectionChange( |
| 286 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 287 | EXPECT_EQ(pc()->ice_connection_state(), new_state); |
| 288 | } |
| 289 | void OnIceGatheringChange( |
| 290 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override { |
| 291 | EXPECT_EQ(pc()->ice_gathering_state(), new_state); |
| 292 | } |
| 293 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
| 294 | LOG(INFO) << id_ << "OnIceCandidate"; |
| 295 | |
| 296 | std::string ice_sdp; |
| 297 | EXPECT_TRUE(candidate->ToString(&ice_sdp)); |
| 298 | if (signaling_message_receiver_ == nullptr) { |
| 299 | // Remote party may be deleted. |
| 300 | return; |
| 301 | } |
| 302 | signaling_message_receiver_->ReceiveIceMessage( |
| 303 | candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); |
| 304 | } |
| 305 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 306 | // MediaStreamInterface callback |
| 307 | void OnChanged() override { |
| 308 | // Track added or removed from MediaStream, so update our renderers. |
| 309 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams = |
| 310 | pc()->remote_streams(); |
| 311 | // Remove renderers for tracks that were removed. |
| 312 | for (auto it = fake_video_renderers_.begin(); |
| 313 | it != fake_video_renderers_.end();) { |
| 314 | if (remote_streams->FindVideoTrack(it->first) == nullptr) { |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 315 | auto to_remove = it++; |
| 316 | removed_fake_video_renderers_.push_back(std::move(to_remove->second)); |
| 317 | fake_video_renderers_.erase(to_remove); |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 318 | } else { |
| 319 | ++it; |
| 320 | } |
| 321 | } |
| 322 | // Create renderers for new video tracks. |
| 323 | for (size_t stream_index = 0; stream_index < remote_streams->count(); |
| 324 | ++stream_index) { |
| 325 | MediaStreamInterface* remote_stream = remote_streams->at(stream_index); |
| 326 | for (size_t track_index = 0; |
| 327 | track_index < remote_stream->GetVideoTracks().size(); |
| 328 | ++track_index) { |
| 329 | const std::string id = |
| 330 | remote_stream->GetVideoTracks()[track_index]->id(); |
| 331 | if (fake_video_renderers_.find(id) != fake_video_renderers_.end()) { |
| 332 | continue; |
| 333 | } |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 334 | fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer( |
| 335 | remote_stream->GetVideoTracks()[track_index])); |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 340 | void SetVideoConstraints(const webrtc::FakeConstraints& video_constraint) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | video_constraints_ = video_constraint; |
| 342 | } |
| 343 | |
| 344 | void AddMediaStream(bool audio, bool video) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 345 | std::string stream_label = |
| 346 | kStreamLabelBase + |
| 347 | rtc::ToString<int>(static_cast<int>(pc()->local_streams()->count())); |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 348 | rtc::scoped_refptr<MediaStreamInterface> stream = |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 349 | peer_connection_factory_->CreateLocalMediaStream(stream_label); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 350 | |
| 351 | if (audio && can_receive_audio()) { |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 352 | stream->AddTrack(CreateLocalAudioTrack(stream_label)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 353 | } |
| 354 | if (video && can_receive_video()) { |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 355 | stream->AddTrack(CreateLocalVideoTrack(stream_label)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | } |
| 357 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 358 | EXPECT_TRUE(pc()->AddStream(stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 359 | } |
| 360 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 361 | size_t NumberOfLocalMediaStreams() { return pc()->local_streams()->count(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 362 | |
| 363 | bool SessionActive() { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 364 | return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | } |
| 366 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 367 | // Automatically add a stream when receiving an offer, if we don't have one. |
| 368 | // Defaults to true. |
| 369 | void set_auto_add_stream(bool auto_add_stream) { |
| 370 | auto_add_stream_ = auto_add_stream; |
| 371 | } |
| 372 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 373 | void set_signaling_message_receiver( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 374 | SignalingMessageReceiver* signaling_message_receiver) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 375 | signaling_message_receiver_ = signaling_message_receiver; |
| 376 | } |
| 377 | |
| 378 | void EnableVideoDecoderFactory() { |
| 379 | video_decoder_factory_enabled_ = true; |
| 380 | fake_video_decoder_factory_->AddSupportedVideoCodecType( |
| 381 | webrtc::kVideoCodecVP8); |
| 382 | } |
| 383 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 384 | void IceRestart() { |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 385 | offer_answer_constraints_.SetMandatoryIceRestart(true); |
| 386 | offer_answer_options_.ice_restart = true; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 387 | SetExpectIceRestart(true); |
| 388 | } |
| 389 | |
| 390 | void SetExpectIceRestart(bool expect_restart) { |
| 391 | expect_ice_restart_ = expect_restart; |
| 392 | } |
| 393 | |
| 394 | bool ExpectIceRestart() const { return expect_ice_restart_; } |
| 395 | |
| 396 | void SetReceiveAudioVideo(bool audio, bool video) { |
| 397 | SetReceiveAudio(audio); |
| 398 | SetReceiveVideo(video); |
| 399 | ASSERT_EQ(audio, can_receive_audio()); |
| 400 | ASSERT_EQ(video, can_receive_video()); |
| 401 | } |
| 402 | |
| 403 | void SetReceiveAudio(bool audio) { |
| 404 | if (audio && can_receive_audio()) |
| 405 | return; |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 406 | offer_answer_constraints_.SetMandatoryReceiveAudio(audio); |
| 407 | offer_answer_options_.offer_to_receive_audio = audio ? 1 : 0; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void SetReceiveVideo(bool video) { |
| 411 | if (video && can_receive_video()) |
| 412 | return; |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 413 | offer_answer_constraints_.SetMandatoryReceiveVideo(video); |
| 414 | offer_answer_options_.offer_to_receive_video = video ? 1 : 0; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | void RemoveMsidFromReceivedSdp(bool remove) { remove_msid_ = remove; } |
| 418 | |
| 419 | void RemoveSdesCryptoFromReceivedSdp(bool remove) { remove_sdes_ = remove; } |
| 420 | |
| 421 | void RemoveBundleFromReceivedSdp(bool remove) { remove_bundle_ = remove; } |
| 422 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 423 | void RemoveCvoFromReceivedSdp(bool remove) { remove_cvo_ = remove; } |
| 424 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 425 | bool can_receive_audio() { |
| 426 | bool value; |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 427 | if (prefer_constraint_apis_) { |
| 428 | if (webrtc::FindConstraint( |
| 429 | &offer_answer_constraints_, |
| 430 | MediaConstraintsInterface::kOfferToReceiveAudio, &value, |
| 431 | nullptr)) { |
| 432 | return value; |
| 433 | } |
| 434 | return true; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 435 | } |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 436 | return offer_answer_options_.offer_to_receive_audio > 0 || |
| 437 | offer_answer_options_.offer_to_receive_audio == |
| 438 | PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | bool can_receive_video() { |
| 442 | bool value; |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 443 | if (prefer_constraint_apis_) { |
| 444 | if (webrtc::FindConstraint( |
| 445 | &offer_answer_constraints_, |
| 446 | MediaConstraintsInterface::kOfferToReceiveVideo, &value, |
| 447 | nullptr)) { |
| 448 | return value; |
| 449 | } |
| 450 | return true; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 451 | } |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 452 | return offer_answer_options_.offer_to_receive_video > 0 || |
| 453 | offer_answer_options_.offer_to_receive_video == |
| 454 | PeerConnectionInterface::RTCOfferAnswerOptions::kUndefined; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 457 | void OnDataChannel( |
| 458 | rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 459 | LOG(INFO) << id_ << "OnDataChannel"; |
| 460 | data_channel_ = data_channel; |
| 461 | data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 462 | } |
| 463 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 464 | void CreateDataChannel() { CreateDataChannel(nullptr); } |
| 465 | |
| 466 | void CreateDataChannel(const webrtc::DataChannelInit* init) { |
| 467 | data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, init); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 468 | ASSERT_TRUE(data_channel_.get() != nullptr); |
| 469 | data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
| 470 | } |
| 471 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 472 | rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( |
| 473 | const std::string& stream_label) { |
| 474 | FakeConstraints constraints; |
| 475 | // Disable highpass filter so that we can get all the test audio frames. |
| 476 | constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 477 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 478 | peer_connection_factory_->CreateAudioSource(&constraints); |
| 479 | // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 480 | // always use the default input. |
| 481 | std::string label = stream_label + kAudioTrackLabelBase; |
| 482 | return peer_connection_factory_->CreateAudioTrack(label, source); |
| 483 | } |
| 484 | |
| 485 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( |
| 486 | const std::string& stream_label) { |
| 487 | // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. |
| 488 | FakeConstraints source_constraints = video_constraints_; |
| 489 | source_constraints.SetMandatoryMaxFrameRate(10); |
| 490 | |
| 491 | cricket::FakeVideoCapturer* fake_capturer = |
| 492 | new webrtc::FakePeriodicVideoCapturer(); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 493 | fake_capturer->SetRotation(capture_rotation_); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 494 | video_capturers_.push_back(fake_capturer); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 495 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 496 | peer_connection_factory_->CreateVideoSource(fake_capturer, |
| 497 | &source_constraints); |
| 498 | std::string label = stream_label + kVideoTrackLabelBase; |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 499 | |
| 500 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track( |
| 501 | peer_connection_factory_->CreateVideoTrack(label, source)); |
| 502 | if (!local_video_renderer_) { |
| 503 | local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track)); |
| 504 | } |
| 505 | return track; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 506 | } |
| 507 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 508 | DataChannelInterface* data_channel() { return data_channel_; } |
| 509 | const MockDataChannelObserver* data_observer() const { |
| 510 | return data_observer_.get(); |
| 511 | } |
| 512 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 513 | webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); } |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 514 | |
| 515 | void StopVideoCapturers() { |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 516 | for (auto* capturer : video_capturers_) { |
| 517 | capturer->Stop(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 521 | void SetCaptureRotation(webrtc::VideoRotation rotation) { |
| 522 | ASSERT_TRUE(video_capturers_.empty()); |
| 523 | capture_rotation_ = rotation; |
| 524 | } |
| 525 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 526 | bool AudioFramesReceivedCheck(int number_of_frames) const { |
| 527 | return number_of_frames <= fake_audio_capture_module_->frames_received(); |
| 528 | } |
| 529 | |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 530 | int audio_frames_received() const { |
| 531 | return fake_audio_capture_module_->frames_received(); |
| 532 | } |
| 533 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 534 | bool VideoFramesReceivedCheck(int number_of_frames) { |
| 535 | if (video_decoder_factory_enabled_) { |
| 536 | const std::vector<FakeWebRtcVideoDecoder*>& decoders |
| 537 | = fake_video_decoder_factory_->decoders(); |
| 538 | if (decoders.empty()) { |
| 539 | return number_of_frames <= 0; |
| 540 | } |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 541 | // Note - this checks that EACH decoder has the requisite number |
| 542 | // of frames. The video_frames_received() function sums them. |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 543 | for (FakeWebRtcVideoDecoder* decoder : decoders) { |
| 544 | if (number_of_frames > decoder->GetNumFramesReceived()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | } |
| 548 | return true; |
| 549 | } else { |
| 550 | if (fake_video_renderers_.empty()) { |
| 551 | return number_of_frames <= 0; |
| 552 | } |
| 553 | |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 554 | for (const auto& pair : fake_video_renderers_) { |
| 555 | if (number_of_frames > pair.second->num_rendered_frames()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | } |
| 559 | return true; |
| 560 | } |
| 561 | } |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 562 | |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 563 | int video_frames_received() const { |
| 564 | int total = 0; |
| 565 | if (video_decoder_factory_enabled_) { |
| 566 | const std::vector<FakeWebRtcVideoDecoder*>& decoders = |
| 567 | fake_video_decoder_factory_->decoders(); |
| 568 | for (const FakeWebRtcVideoDecoder* decoder : decoders) { |
| 569 | total += decoder->GetNumFramesReceived(); |
| 570 | } |
| 571 | } else { |
| 572 | for (const auto& pair : fake_video_renderers_) { |
| 573 | total += pair.second->num_rendered_frames(); |
| 574 | } |
| 575 | for (const auto& renderer : removed_fake_video_renderers_) { |
| 576 | total += renderer->num_rendered_frames(); |
| 577 | } |
| 578 | } |
| 579 | return total; |
| 580 | } |
| 581 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | // Verify the CreateDtmfSender interface |
| 583 | void VerifyDtmf() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 584 | std::unique_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 585 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 586 | |
| 587 | // We can't create a DTMF sender with an invalid audio track or a non local |
| 588 | // track. |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 589 | EXPECT_TRUE(peer_connection_->CreateDtmfSender(nullptr) == nullptr); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 590 | rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 591 | peer_connection_factory_->CreateAudioTrack("dummy_track", nullptr)); |
| 592 | EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 593 | |
| 594 | // We should be able to create a DTMF sender from a local track. |
| 595 | webrtc::AudioTrackInterface* localtrack = |
| 596 | peer_connection_->local_streams()->at(0)->GetAudioTracks()[0]; |
| 597 | dtmf_sender = peer_connection_->CreateDtmfSender(localtrack); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 598 | EXPECT_TRUE(dtmf_sender.get() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 599 | dtmf_sender->RegisterObserver(observer.get()); |
| 600 | |
| 601 | // Test the DtmfSender object just created. |
| 602 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 603 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 604 | |
| 605 | // We don't need to verify that the DTMF tones are actually sent out because |
| 606 | // that is already covered by the tests of the lower level components. |
| 607 | |
| 608 | EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs); |
| 609 | std::vector<std::string> tones; |
| 610 | tones.push_back("1"); |
| 611 | tones.push_back("a"); |
| 612 | tones.push_back(""); |
| 613 | observer->Verify(tones); |
| 614 | |
| 615 | dtmf_sender->UnregisterObserver(); |
| 616 | } |
| 617 | |
| 618 | // Verifies that the SessionDescription have rejected the appropriate media |
| 619 | // content. |
| 620 | void VerifyRejectedMediaInSessionDescription() { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 621 | ASSERT_TRUE(peer_connection_->remote_description() != nullptr); |
| 622 | ASSERT_TRUE(peer_connection_->local_description() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 623 | const cricket::SessionDescription* remote_desc = |
| 624 | peer_connection_->remote_description()->description(); |
| 625 | const cricket::SessionDescription* local_desc = |
| 626 | peer_connection_->local_description()->description(); |
| 627 | |
| 628 | const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc); |
| 629 | if (remote_audio_content) { |
| 630 | const ContentInfo* audio_content = |
| 631 | GetFirstAudioContent(local_desc); |
| 632 | EXPECT_EQ(can_receive_audio(), !audio_content->rejected); |
| 633 | } |
| 634 | |
| 635 | const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc); |
| 636 | if (remote_video_content) { |
| 637 | const ContentInfo* video_content = |
| 638 | GetFirstVideoContent(local_desc); |
| 639 | EXPECT_EQ(can_receive_video(), !video_content->rejected); |
| 640 | } |
| 641 | } |
| 642 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 643 | void VerifyLocalIceUfragAndPassword() { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 644 | ASSERT_TRUE(peer_connection_->local_description() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 645 | const cricket::SessionDescription* desc = |
| 646 | peer_connection_->local_description()->description(); |
| 647 | const cricket::ContentInfos& contents = desc->contents(); |
| 648 | |
| 649 | for (size_t index = 0; index < contents.size(); ++index) { |
| 650 | if (contents[index].rejected) |
| 651 | continue; |
| 652 | const cricket::TransportDescription* transport_desc = |
| 653 | desc->GetTransportDescriptionByName(contents[index].name); |
| 654 | |
| 655 | std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 656 | ice_ufrag_pwd_.find(static_cast<int>(index)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 657 | if (ufragpair_it == ice_ufrag_pwd_.end()) { |
| 658 | ASSERT_FALSE(ExpectIceRestart()); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 659 | ice_ufrag_pwd_[static_cast<int>(index)] = |
| 660 | IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 661 | } else if (ExpectIceRestart()) { |
| 662 | const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second; |
| 663 | EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag); |
| 664 | EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd); |
| 665 | } else { |
| 666 | const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second; |
| 667 | EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag); |
| 668 | EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 674 | rtc::scoped_refptr<MockStatsObserver> |
| 675 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 676 | EXPECT_TRUE(peer_connection_->GetStats( |
| 677 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 678 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 679 | EXPECT_NE(0, observer->timestamp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 680 | return observer->AudioOutputLevel(); |
| 681 | } |
| 682 | |
| 683 | int GetAudioInputLevelStats() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 684 | rtc::scoped_refptr<MockStatsObserver> |
| 685 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 686 | EXPECT_TRUE(peer_connection_->GetStats( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 687 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 688 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 689 | EXPECT_NE(0, observer->timestamp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | return observer->AudioInputLevel(); |
| 691 | } |
| 692 | |
| 693 | int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 694 | rtc::scoped_refptr<MockStatsObserver> |
| 695 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 696 | EXPECT_TRUE(peer_connection_->GetStats( |
| 697 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 698 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 699 | EXPECT_NE(0, observer->timestamp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | return observer->BytesReceived(); |
| 701 | } |
| 702 | |
| 703 | int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 704 | rtc::scoped_refptr<MockStatsObserver> |
| 705 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 706 | EXPECT_TRUE(peer_connection_->GetStats( |
| 707 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 708 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 709 | EXPECT_NE(0, observer->timestamp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 710 | return observer->BytesSent(); |
| 711 | } |
| 712 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 713 | int GetAvailableReceivedBandwidthStats() { |
| 714 | rtc::scoped_refptr<MockStatsObserver> |
| 715 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
| 716 | EXPECT_TRUE(peer_connection_->GetStats( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 717 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 718 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 719 | EXPECT_NE(0, observer->timestamp()); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 720 | int bw = observer->AvailableReceiveBandwidth(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 721 | return bw; |
| 722 | } |
| 723 | |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 724 | std::string GetDtlsCipherStats() { |
| 725 | rtc::scoped_refptr<MockStatsObserver> |
| 726 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
| 727 | EXPECT_TRUE(peer_connection_->GetStats( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 728 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 729 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 730 | EXPECT_NE(0, observer->timestamp()); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 731 | return observer->DtlsCipher(); |
| 732 | } |
| 733 | |
| 734 | std::string GetSrtpCipherStats() { |
| 735 | rtc::scoped_refptr<MockStatsObserver> |
| 736 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
| 737 | EXPECT_TRUE(peer_connection_->GetStats( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 738 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 739 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 740 | EXPECT_NE(0, observer->timestamp()); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 741 | return observer->SrtpCipher(); |
| 742 | } |
| 743 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 744 | int rendered_width() { |
| 745 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 746 | return fake_video_renderers_.empty() ? 1 : |
| 747 | fake_video_renderers_.begin()->second->width(); |
| 748 | } |
| 749 | |
| 750 | int rendered_height() { |
| 751 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 752 | return fake_video_renderers_.empty() ? 1 : |
| 753 | fake_video_renderers_.begin()->second->height(); |
| 754 | } |
| 755 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 756 | webrtc::VideoRotation rendered_rotation() { |
| 757 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 758 | return fake_video_renderers_.empty() |
| 759 | ? webrtc::kVideoRotation_0 |
| 760 | : fake_video_renderers_.begin()->second->rotation(); |
| 761 | } |
| 762 | |
| 763 | int local_rendered_width() { |
| 764 | return local_video_renderer_ ? local_video_renderer_->width() : 1; |
| 765 | } |
| 766 | |
| 767 | int local_rendered_height() { |
| 768 | return local_video_renderer_ ? local_video_renderer_->height() : 1; |
| 769 | } |
| 770 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 771 | size_t number_of_remote_streams() { |
| 772 | if (!pc()) |
| 773 | return 0; |
| 774 | return pc()->remote_streams()->count(); |
| 775 | } |
| 776 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 777 | StreamCollectionInterface* remote_streams() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 778 | if (!pc()) { |
| 779 | ADD_FAILURE(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 780 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 781 | } |
| 782 | return pc()->remote_streams(); |
| 783 | } |
| 784 | |
| 785 | StreamCollectionInterface* local_streams() { |
| 786 | if (!pc()) { |
| 787 | ADD_FAILURE(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 788 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 789 | } |
| 790 | return pc()->local_streams(); |
| 791 | } |
| 792 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 793 | bool HasLocalAudioTrack() { return StreamsHaveAudioTrack(local_streams()); } |
| 794 | |
| 795 | bool HasLocalVideoTrack() { return StreamsHaveVideoTrack(local_streams()); } |
| 796 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 797 | webrtc::PeerConnectionInterface::SignalingState signaling_state() { |
| 798 | return pc()->signaling_state(); |
| 799 | } |
| 800 | |
| 801 | webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
| 802 | return pc()->ice_connection_state(); |
| 803 | } |
| 804 | |
| 805 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 806 | return pc()->ice_gathering_state(); |
| 807 | } |
| 808 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 809 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> const& |
| 810 | rtp_receiver_observers() { |
| 811 | return rtp_receiver_observers_; |
| 812 | } |
| 813 | |
| 814 | void SetRtpReceiverObservers() { |
| 815 | rtp_receiver_observers_.clear(); |
| 816 | for (auto receiver : pc()->GetReceivers()) { |
| 817 | std::unique_ptr<MockRtpReceiverObserver> observer( |
| 818 | new MockRtpReceiverObserver(receiver->media_type())); |
| 819 | receiver->SetObserver(observer.get()); |
| 820 | rtp_receiver_observers_.push_back(std::move(observer)); |
| 821 | } |
| 822 | } |
| 823 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 824 | private: |
| 825 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 826 | public: |
| 827 | DummyDtmfObserver() : completed_(false) {} |
| 828 | |
| 829 | // Implements DtmfSenderObserverInterface. |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 830 | void OnToneChange(const std::string& tone) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 831 | tones_.push_back(tone); |
| 832 | if (tone.empty()) { |
| 833 | completed_ = true; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | void Verify(const std::vector<std::string>& tones) const { |
| 838 | ASSERT_TRUE(tones_.size() == tones.size()); |
| 839 | EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin())); |
| 840 | } |
| 841 | |
| 842 | bool completed() const { return completed_; } |
| 843 | |
| 844 | private: |
| 845 | bool completed_; |
| 846 | std::vector<std::string> tones_; |
| 847 | }; |
| 848 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 849 | explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
| 850 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 851 | bool Init( |
| 852 | const MediaConstraintsInterface* constraints, |
| 853 | const PeerConnectionFactory::Options* options, |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 854 | const PeerConnectionInterface::RTCConfiguration& config, |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 855 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 856 | bool prefer_constraint_apis, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 857 | rtc::Thread* network_thread, |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 858 | rtc::Thread* worker_thread) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 859 | EXPECT_TRUE(!peer_connection_); |
| 860 | EXPECT_TRUE(!peer_connection_factory_); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 861 | if (!prefer_constraint_apis) { |
| 862 | EXPECT_TRUE(!constraints); |
| 863 | } |
| 864 | prefer_constraint_apis_ = prefer_constraint_apis; |
| 865 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 866 | std::unique_ptr<cricket::PortAllocator> port_allocator( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 867 | new cricket::FakePortAllocator(network_thread, nullptr)); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 868 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 869 | |
| 870 | if (fake_audio_capture_module_ == nullptr) { |
| 871 | return false; |
| 872 | } |
| 873 | fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); |
| 874 | fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 875 | rtc::Thread* const signaling_thread = rtc::Thread::Current(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 876 | peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 877 | network_thread, worker_thread, signaling_thread, |
| 878 | fake_audio_capture_module_, fake_video_encoder_factory_, |
| 879 | fake_video_decoder_factory_); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 880 | if (!peer_connection_factory_) { |
| 881 | return false; |
| 882 | } |
| 883 | if (options) { |
| 884 | peer_connection_factory_->SetOptions(*options); |
| 885 | } |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 886 | peer_connection_ = |
| 887 | CreatePeerConnection(std::move(port_allocator), constraints, config, |
| 888 | std::move(cert_generator)); |
| 889 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 890 | return peer_connection_.get() != nullptr; |
| 891 | } |
| 892 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 893 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 894 | std::unique_ptr<cricket::PortAllocator> port_allocator, |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 895 | const MediaConstraintsInterface* constraints, |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 896 | const PeerConnectionInterface::RTCConfiguration& config, |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 897 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 898 | return peer_connection_factory_->CreatePeerConnection( |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 899 | config, constraints, std::move(port_allocator), |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 900 | std::move(cert_generator), this); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | void HandleIncomingOffer(const std::string& msg) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 904 | LOG(INFO) << id_ << "HandleIncomingOffer "; |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 905 | if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 906 | // If we are not sending any streams ourselves it is time to add some. |
| 907 | AddMediaStream(true, true); |
| 908 | } |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 909 | std::unique_ptr<SessionDescriptionInterface> desc( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 910 | webrtc::CreateSessionDescription("offer", msg, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 911 | EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 912 | // Set the RtpReceiverObserver after receivers are created. |
| 913 | SetRtpReceiverObservers(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 914 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 915 | EXPECT_TRUE(DoCreateAnswer(&answer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 916 | std::string sdp; |
| 917 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 918 | EXPECT_TRUE(DoSetLocalDescription(answer.release())); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 919 | if (signaling_message_receiver_) { |
| 920 | signaling_message_receiver_->ReceiveSdpMessage( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 921 | webrtc::SessionDescriptionInterface::kAnswer, sdp); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | void HandleIncomingAnswer(const std::string& msg) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 926 | LOG(INFO) << id_ << "HandleIncomingAnswer"; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 927 | std::unique_ptr<SessionDescriptionInterface> desc( |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 928 | webrtc::CreateSessionDescription("answer", msg, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 930 | // Set the RtpReceiverObserver after receivers are created. |
| 931 | SetRtpReceiverObservers(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 932 | } |
| 933 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 934 | bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 935 | bool offer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 936 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> |
| 937 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 938 | MockCreateSessionDescriptionObserver>()); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 939 | if (prefer_constraint_apis_) { |
| 940 | if (offer) { |
| 941 | pc()->CreateOffer(observer, &offer_answer_constraints_); |
| 942 | } else { |
| 943 | pc()->CreateAnswer(observer, &offer_answer_constraints_); |
| 944 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 945 | } else { |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 946 | if (offer) { |
| 947 | pc()->CreateOffer(observer, offer_answer_options_); |
| 948 | } else { |
| 949 | pc()->CreateAnswer(observer, offer_answer_options_); |
| 950 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 951 | } |
| 952 | EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs); |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 953 | desc->reset(observer->release_desc()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 954 | if (observer->result() && ExpectIceRestart()) { |
| 955 | EXPECT_EQ(0u, (*desc)->candidates(0)->count()); |
| 956 | } |
| 957 | return observer->result(); |
| 958 | } |
| 959 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 960 | bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 961 | return DoCreateOfferAnswer(desc, true); |
| 962 | } |
| 963 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 964 | bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 965 | return DoCreateOfferAnswer(desc, false); |
| 966 | } |
| 967 | |
| 968 | bool DoSetLocalDescription(SessionDescriptionInterface* desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 969 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
| 970 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 971 | MockSetSessionDescriptionObserver>()); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 972 | LOG(INFO) << id_ << "SetLocalDescription "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 973 | pc()->SetLocalDescription(observer, desc); |
| 974 | // Ignore the observer result. If we wait for the result with |
| 975 | // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer |
| 976 | // before the offer which is an error. |
| 977 | // The reason is that EXPECT_TRUE_WAIT uses |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 978 | // rtc::Thread::Current()->ProcessMessages(1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 979 | // ProcessMessages waits at least 1ms but processes all messages before |
| 980 | // returning. Since this test is synchronous and send messages to the remote |
| 981 | // peer whenever a callback is invoked, this can lead to messages being |
| 982 | // sent to the remote peer in the wrong order. |
| 983 | // TODO(perkj): Find a way to check the result without risking that the |
| 984 | // order of sent messages are changed. Ex- by posting all messages that are |
| 985 | // sent to the remote peer. |
| 986 | return true; |
| 987 | } |
| 988 | |
| 989 | bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 990 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
| 991 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 992 | MockSetSessionDescriptionObserver>()); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 993 | LOG(INFO) << id_ << "SetRemoteDescription "; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 994 | pc()->SetRemoteDescription(observer, desc); |
| 995 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 996 | return observer->result(); |
| 997 | } |
| 998 | |
| 999 | // This modifies all received SDP messages before they are processed. |
| 1000 | void FilterIncomingSdpMessage(std::string* sdp) { |
| 1001 | if (remove_msid_) { |
| 1002 | const char kSdpSsrcAttribute[] = "a=ssrc:"; |
| 1003 | RemoveLinesFromSdp(kSdpSsrcAttribute, sdp); |
| 1004 | const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:"; |
| 1005 | RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp); |
| 1006 | } |
| 1007 | if (remove_bundle_) { |
| 1008 | const char kSdpBundleAttribute[] = "a=group:BUNDLE"; |
| 1009 | RemoveLinesFromSdp(kSdpBundleAttribute, sdp); |
| 1010 | } |
| 1011 | if (remove_sdes_) { |
| 1012 | const char kSdpSdesCryptoAttribute[] = "a=crypto"; |
| 1013 | RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); |
| 1014 | } |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1015 | if (remove_cvo_) { |
| 1016 | const char kSdpCvoExtenstion[] = "urn:3gpp:video-orientation"; |
| 1017 | RemoveLinesFromSdp(kSdpCvoExtenstion, sdp); |
| 1018 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1021 | std::string id_; |
| 1022 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1023 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 1024 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 1025 | peer_connection_factory_; |
| 1026 | |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1027 | bool prefer_constraint_apis_ = true; |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 1028 | bool auto_add_stream_ = true; |
| 1029 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1030 | typedef std::pair<std::string, std::string> IceUfragPwdPair; |
| 1031 | std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; |
| 1032 | bool expect_ice_restart_ = false; |
| 1033 | |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1034 | // Needed to keep track of number of frames sent. |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1035 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
| 1036 | // Needed to keep track of number of frames received. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1037 | std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1038 | fake_video_renderers_; |
| 1039 | // Needed to ensure frames aren't received for removed tracks. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1040 | std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1041 | removed_fake_video_renderers_; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1042 | // Needed to keep track of number of frames received when external decoder |
| 1043 | // used. |
| 1044 | FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr; |
| 1045 | FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr; |
| 1046 | bool video_decoder_factory_enabled_ = false; |
| 1047 | webrtc::FakeConstraints video_constraints_; |
| 1048 | |
| 1049 | // For remote peer communication. |
| 1050 | SignalingMessageReceiver* signaling_message_receiver_ = nullptr; |
| 1051 | |
| 1052 | // Store references to the video capturers we've created, so that we can stop |
| 1053 | // them, if required. |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1054 | std::vector<cricket::FakeVideoCapturer*> video_capturers_; |
| 1055 | webrtc::VideoRotation capture_rotation_ = webrtc::kVideoRotation_0; |
| 1056 | // |local_video_renderer_| attached to the first created local video track. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1057 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1058 | |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1059 | webrtc::FakeConstraints offer_answer_constraints_; |
| 1060 | PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1061 | bool remove_msid_ = false; // True if MSID should be removed in received SDP. |
| 1062 | bool remove_bundle_ = |
| 1063 | false; // True if bundle should be removed in received SDP. |
| 1064 | bool remove_sdes_ = |
| 1065 | false; // True if a=crypto should be removed in received SDP. |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1066 | // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be |
| 1067 | // removed in the received SDP. |
| 1068 | bool remove_cvo_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1069 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1070 | rtc::scoped_refptr<DataChannelInterface> data_channel_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1071 | std::unique_ptr<MockDataChannelObserver> data_observer_; |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 1072 | |
| 1073 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1074 | }; |
| 1075 | |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1076 | class P2PTestConductor : public testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1077 | public: |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1078 | P2PTestConductor() |
deadbeef | eff5b85 | 2016-05-27 14:18:01 -0700 | [diff] [blame] | 1079 | : pss_(new rtc::PhysicalSocketServer), |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 1080 | ss_(new rtc::VirtualSocketServer(pss_.get())), |
deadbeef | eff5b85 | 2016-05-27 14:18:01 -0700 | [diff] [blame] | 1081 | network_thread_(new rtc::Thread(ss_.get())), |
| 1082 | worker_thread_(rtc::Thread::Create()) { |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 1083 | RTC_CHECK(network_thread_->Start()); |
| 1084 | RTC_CHECK(worker_thread_->Start()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1085 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 1086 | ice_server.uri = "stun:stun.l.google.com:19302"; |
| 1087 | config_.servers.push_back(ice_server); |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 1088 | } |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 1089 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1090 | bool SessionActive() { |
| 1091 | return initiating_client_->SessionActive() && |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 1092 | receiving_client_->SessionActive(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1093 | } |
pbos@webrtc.org | 9eacb8c | 2015-01-02 09:03:19 +0000 | [diff] [blame] | 1094 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1095 | // Return true if the number of frames provided have been received |
| 1096 | // on the video and audio tracks provided. |
| 1097 | bool FramesHaveArrived(int audio_frames_to_receive, |
| 1098 | int video_frames_to_receive) { |
| 1099 | bool all_good = true; |
| 1100 | if (initiating_client_->HasLocalAudioTrack() && |
| 1101 | receiving_client_->can_receive_audio()) { |
| 1102 | all_good &= |
| 1103 | receiving_client_->AudioFramesReceivedCheck(audio_frames_to_receive); |
| 1104 | } |
| 1105 | if (initiating_client_->HasLocalVideoTrack() && |
| 1106 | receiving_client_->can_receive_video()) { |
| 1107 | all_good &= |
| 1108 | receiving_client_->VideoFramesReceivedCheck(video_frames_to_receive); |
| 1109 | } |
| 1110 | if (receiving_client_->HasLocalAudioTrack() && |
| 1111 | initiating_client_->can_receive_audio()) { |
| 1112 | all_good &= |
| 1113 | initiating_client_->AudioFramesReceivedCheck(audio_frames_to_receive); |
| 1114 | } |
| 1115 | if (receiving_client_->HasLocalVideoTrack() && |
| 1116 | initiating_client_->can_receive_video()) { |
| 1117 | all_good &= |
| 1118 | initiating_client_->VideoFramesReceivedCheck(video_frames_to_receive); |
| 1119 | } |
| 1120 | return all_good; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1121 | } |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1122 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1123 | void VerifyDtmf() { |
| 1124 | initiating_client_->VerifyDtmf(); |
| 1125 | receiving_client_->VerifyDtmf(); |
| 1126 | } |
| 1127 | |
| 1128 | void TestUpdateOfferWithRejectedContent() { |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1129 | // Renegotiate, rejecting the video m-line. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1130 | initiating_client_->Negotiate(true, false); |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1131 | ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 1132 | |
| 1133 | int pc1_audio_received = initiating_client_->audio_frames_received(); |
| 1134 | int pc1_video_received = initiating_client_->video_frames_received(); |
| 1135 | int pc2_audio_received = receiving_client_->audio_frames_received(); |
| 1136 | int pc2_video_received = receiving_client_->video_frames_received(); |
| 1137 | |
| 1138 | // Wait for some additional audio frames to be received. |
| 1139 | EXPECT_TRUE_WAIT(initiating_client_->AudioFramesReceivedCheck( |
| 1140 | pc1_audio_received + kEndAudioFrameCount) && |
| 1141 | receiving_client_->AudioFramesReceivedCheck( |
| 1142 | pc2_audio_received + kEndAudioFrameCount), |
| 1143 | kMaxWaitForFramesMs); |
| 1144 | |
| 1145 | // During this time, we shouldn't have received any additional video frames |
| 1146 | // for the rejected video tracks. |
| 1147 | EXPECT_EQ(pc1_video_received, initiating_client_->video_frames_received()); |
| 1148 | EXPECT_EQ(pc2_video_received, receiving_client_->video_frames_received()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | void VerifyRenderedSize(int width, int height) { |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1152 | VerifyRenderedSize(width, height, webrtc::kVideoRotation_0); |
| 1153 | } |
| 1154 | |
| 1155 | void VerifyRenderedSize(int width, |
| 1156 | int height, |
| 1157 | webrtc::VideoRotation rotation) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1158 | EXPECT_EQ(width, receiving_client()->rendered_width()); |
| 1159 | EXPECT_EQ(height, receiving_client()->rendered_height()); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1160 | EXPECT_EQ(rotation, receiving_client()->rendered_rotation()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1161 | EXPECT_EQ(width, initializing_client()->rendered_width()); |
| 1162 | EXPECT_EQ(height, initializing_client()->rendered_height()); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1163 | EXPECT_EQ(rotation, initializing_client()->rendered_rotation()); |
| 1164 | |
| 1165 | // Verify size of the local preview. |
| 1166 | EXPECT_EQ(width, initializing_client()->local_rendered_width()); |
| 1167 | EXPECT_EQ(height, initializing_client()->local_rendered_height()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | void VerifySessionDescriptions() { |
| 1171 | initiating_client_->VerifyRejectedMediaInSessionDescription(); |
| 1172 | receiving_client_->VerifyRejectedMediaInSessionDescription(); |
| 1173 | initiating_client_->VerifyLocalIceUfragAndPassword(); |
| 1174 | receiving_client_->VerifyLocalIceUfragAndPassword(); |
| 1175 | } |
| 1176 | |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1177 | ~P2PTestConductor() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1178 | if (initiating_client_) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1179 | initiating_client_->set_signaling_message_receiver(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1180 | } |
| 1181 | if (receiving_client_) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1182 | receiving_client_->set_signaling_message_receiver(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1183 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1186 | bool CreateTestClients() { return CreateTestClients(nullptr, nullptr); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1187 | |
| 1188 | bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 1189 | MediaConstraintsInterface* recv_constraints) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1190 | return CreateTestClients(init_constraints, nullptr, recv_constraints, |
| 1191 | nullptr); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1194 | bool CreateTestClientsThatPreferNoConstraints() { |
| 1195 | initiating_client_.reset( |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 1196 | PeerConnectionTestClient::CreateClientPreferNoConstraints( |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1197 | "Caller: ", nullptr, config_, network_thread_.get(), |
| 1198 | worker_thread_.get())); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1199 | receiving_client_.reset( |
perkj | 8aba997 | 2016-04-10 23:54:34 -0700 | [diff] [blame] | 1200 | PeerConnectionTestClient::CreateClientPreferNoConstraints( |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1201 | "Callee: ", nullptr, config_, network_thread_.get(), |
| 1202 | worker_thread_.get())); |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1203 | if (!initiating_client_ || !receiving_client_) { |
| 1204 | return false; |
| 1205 | } |
| 1206 | // Remember the choice for possible later resets of the clients. |
| 1207 | prefer_constraint_apis_ = false; |
| 1208 | SetSignalingReceivers(); |
| 1209 | return true; |
| 1210 | } |
| 1211 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1212 | void SetSignalingReceivers() { |
| 1213 | initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| 1214 | receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| 1215 | } |
| 1216 | |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1217 | bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 1218 | PeerConnectionFactory::Options* init_options, |
| 1219 | MediaConstraintsInterface* recv_constraints, |
| 1220 | PeerConnectionFactory::Options* recv_options) { |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1221 | initiating_client_.reset(PeerConnectionTestClient::CreateClient( |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1222 | "Caller: ", init_constraints, init_options, config_, |
| 1223 | network_thread_.get(), worker_thread_.get())); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1224 | receiving_client_.reset(PeerConnectionTestClient::CreateClient( |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1225 | "Callee: ", recv_constraints, recv_options, config_, |
| 1226 | network_thread_.get(), worker_thread_.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1227 | if (!initiating_client_ || !receiving_client_) { |
| 1228 | return false; |
| 1229 | } |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1230 | SetSignalingReceivers(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1231 | return true; |
| 1232 | } |
| 1233 | |
| 1234 | void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, |
| 1235 | const webrtc::FakeConstraints& recv_constraints) { |
| 1236 | initiating_client_->SetVideoConstraints(init_constraints); |
| 1237 | receiving_client_->SetVideoConstraints(recv_constraints); |
| 1238 | } |
| 1239 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1240 | void SetCaptureRotation(webrtc::VideoRotation rotation) { |
| 1241 | initiating_client_->SetCaptureRotation(rotation); |
| 1242 | receiving_client_->SetCaptureRotation(rotation); |
| 1243 | } |
| 1244 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1245 | void EnableVideoDecoderFactory() { |
| 1246 | initiating_client_->EnableVideoDecoderFactory(); |
| 1247 | receiving_client_->EnableVideoDecoderFactory(); |
| 1248 | } |
| 1249 | |
| 1250 | // This test sets up a call between two parties. Both parties send static |
| 1251 | // frames to each other. Once the test is finished the number of sent frames |
| 1252 | // is compared to the number of received frames. |
Taylor Brandstetter | 0a1bc53 | 2016-04-19 18:03:26 -0700 | [diff] [blame] | 1253 | void LocalP2PTest() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1254 | if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
| 1255 | initiating_client_->AddMediaStream(true, true); |
| 1256 | } |
| 1257 | initiating_client_->Negotiate(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1258 | // Assert true is used here since next tests are guaranteed to fail and |
| 1259 | // would eat up 5 seconds. |
| 1260 | ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 1261 | VerifySessionDescriptions(); |
| 1262 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1263 | int audio_frame_count = kEndAudioFrameCount; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1264 | int video_frame_count = kEndVideoFrameCount; |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1265 | // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
| 1266 | |
| 1267 | if ((!initiating_client_->can_receive_audio() && |
| 1268 | !initiating_client_->can_receive_video()) || |
| 1269 | (!receiving_client_->can_receive_audio() && |
| 1270 | !receiving_client_->can_receive_video())) { |
| 1271 | // Neither audio nor video will flow, so connections won't be |
| 1272 | // established. There's nothing more to check. |
| 1273 | // TODO(hta): Check connection if there's a data channel. |
| 1274 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1277 | // Audio or video is expected to flow, so both clients should reach the |
| 1278 | // Connected state, and the offerer (ICE controller) should proceed to |
| 1279 | // Completed. |
| 1280 | // Note: These tests have been observed to fail under heavy load at |
| 1281 | // shorter timeouts, so they may be flaky. |
Taylor Brandstetter | 0a1bc53 | 2016-04-19 18:03:26 -0700 | [diff] [blame] | 1282 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 1283 | initiating_client_->ice_connection_state(), |
| 1284 | kMaxWaitForFramesMs); |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1285 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1286 | receiving_client_->ice_connection_state(), |
| 1287 | kMaxWaitForFramesMs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1288 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1289 | // The ICE gathering state should end up in kIceGatheringComplete, |
| 1290 | // but there's a bug that prevents this at the moment, and the state |
| 1291 | // machine is being updated by the WEBRTC WG. |
| 1292 | // TODO(hta): Update this check when spec revisions finish. |
| 1293 | EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew, |
| 1294 | initiating_client_->ice_gathering_state()); |
| 1295 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 1296 | receiving_client_->ice_gathering_state(), |
| 1297 | kMaxWaitForFramesMs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1298 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1299 | // Check that the expected number of frames have arrived. |
| 1300 | EXPECT_TRUE_WAIT(FramesHaveArrived(audio_frame_count, video_frame_count), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1301 | kMaxWaitForFramesMs); |
| 1302 | } |
| 1303 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1304 | void SetupAndVerifyDtlsCall() { |
| 1305 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 1306 | FakeConstraints setup_constraints; |
| 1307 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1308 | true); |
| 1309 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1310 | LocalP2PTest(); |
| 1311 | VerifyRenderedSize(640, 480); |
| 1312 | } |
| 1313 | |
| 1314 | PeerConnectionTestClient* CreateDtlsClientWithAlternateKey() { |
| 1315 | FakeConstraints setup_constraints; |
| 1316 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1317 | true); |
| 1318 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 1319 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 1320 | rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
| 1321 | new FakeRTCCertificateGenerator() : nullptr); |
| 1322 | cert_generator->use_alternate_key(); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1323 | |
| 1324 | // Make sure the new client is using a different certificate. |
| 1325 | return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore( |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1326 | "New Peer: ", &setup_constraints, nullptr, config_, |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 1327 | std::move(cert_generator), prefer_constraint_apis_, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 1328 | network_thread_.get(), worker_thread_.get()); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1331 | void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
| 1332 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1333 | // times to avoid test flakiness. |
| 1334 | static const size_t kSendAttempts = 5; |
| 1335 | |
| 1336 | for (size_t i = 0; i < kSendAttempts; ++i) { |
| 1337 | dc->Send(DataBuffer(data)); |
| 1338 | } |
| 1339 | } |
| 1340 | |
Taylor Brandstetter | 9b5306c | 2016-08-18 11:40:37 -0700 | [diff] [blame^] | 1341 | rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1342 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1343 | PeerConnectionTestClient* initializing_client() { |
| 1344 | return initiating_client_.get(); |
| 1345 | } |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1346 | |
| 1347 | // Set the |initiating_client_| to the |client| passed in and return the |
| 1348 | // original |initiating_client_|. |
| 1349 | PeerConnectionTestClient* set_initializing_client( |
| 1350 | PeerConnectionTestClient* client) { |
| 1351 | PeerConnectionTestClient* old = initiating_client_.release(); |
| 1352 | initiating_client_.reset(client); |
| 1353 | return old; |
| 1354 | } |
| 1355 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1356 | PeerConnectionTestClient* receiving_client() { |
| 1357 | return receiving_client_.get(); |
| 1358 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1359 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1360 | // Set the |receiving_client_| to the |client| passed in and return the |
| 1361 | // original |receiving_client_|. |
| 1362 | PeerConnectionTestClient* set_receiving_client( |
| 1363 | PeerConnectionTestClient* client) { |
| 1364 | PeerConnectionTestClient* old = receiving_client_.release(); |
| 1365 | receiving_client_.reset(client); |
| 1366 | return old; |
| 1367 | } |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1368 | webrtc::PeerConnectionInterface::RTCConfiguration* config() { |
| 1369 | return &config_; |
| 1370 | } |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1371 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 1372 | bool AllObserversReceived( |
| 1373 | const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) { |
| 1374 | for (auto& observer : observers) { |
| 1375 | if (!observer->first_packet_received()) { |
| 1376 | return false; |
| 1377 | } |
| 1378 | } |
| 1379 | return true; |
| 1380 | } |
| 1381 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1382 | void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled, |
| 1383 | int expected_cipher_suite) { |
| 1384 | PeerConnectionFactory::Options init_options; |
| 1385 | init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled; |
| 1386 | PeerConnectionFactory::Options recv_options; |
| 1387 | recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled; |
| 1388 | ASSERT_TRUE( |
| 1389 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
| 1390 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1391 | init_observer = |
| 1392 | new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1393 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
| 1394 | LocalP2PTest(); |
| 1395 | |
| 1396 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
| 1397 | initializing_client()->GetSrtpCipherStats(), |
| 1398 | kMaxWaitMs); |
| 1399 | EXPECT_EQ(1, |
| 1400 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1401 | expected_cipher_suite)); |
| 1402 | } |
| 1403 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1404 | private: |
deadbeef | eff5b85 | 2016-05-27 14:18:01 -0700 | [diff] [blame] | 1405 | // |ss_| is used by |network_thread_| so it must be destroyed later. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1406 | std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 1407 | std::unique_ptr<rtc::VirtualSocketServer> ss_; |
deadbeef | eff5b85 | 2016-05-27 14:18:01 -0700 | [diff] [blame] | 1408 | // |network_thread_| and |worker_thread_| are used by both |
| 1409 | // |initiating_client_| and |receiving_client_| so they must be destroyed |
| 1410 | // later. |
| 1411 | std::unique_ptr<rtc::Thread> network_thread_; |
| 1412 | std::unique_ptr<rtc::Thread> worker_thread_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1413 | std::unique_ptr<PeerConnectionTestClient> initiating_client_; |
| 1414 | std::unique_ptr<PeerConnectionTestClient> receiving_client_; |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1415 | bool prefer_constraint_apis_ = true; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1416 | webrtc::PeerConnectionInterface::RTCConfiguration config_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1417 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1418 | |
kjellander@webrtc.org | d1cfa71 | 2013-10-16 16:51:52 +0000 | [diff] [blame] | 1419 | // Disable for TSan v2, see |
| 1420 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 1421 | #if !defined(THREAD_SANITIZER) |
| 1422 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 1423 | TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) { |
| 1424 | ASSERT_TRUE(CreateTestClients()); |
| 1425 | LocalP2PTest(); |
| 1426 | EXPECT_TRUE_WAIT( |
| 1427 | AllObserversReceived(initializing_client()->rtp_receiver_observers()), |
| 1428 | kMaxWaitForFramesMs); |
| 1429 | EXPECT_TRUE_WAIT( |
| 1430 | AllObserversReceived(receiving_client()->rtp_receiver_observers()), |
| 1431 | kMaxWaitForFramesMs); |
| 1432 | } |
| 1433 | |
| 1434 | // The observers are expected to fire the signal even if they are set after the |
| 1435 | // first packet is received. |
| 1436 | TEST_F(P2PTestConductor, TestSetRtpReceiverObserverAfterFirstPacketIsReceived) { |
| 1437 | ASSERT_TRUE(CreateTestClients()); |
| 1438 | LocalP2PTest(); |
| 1439 | // Reset the RtpReceiverObservers. |
| 1440 | initializing_client()->SetRtpReceiverObservers(); |
| 1441 | receiving_client()->SetRtpReceiverObservers(); |
| 1442 | EXPECT_TRUE_WAIT( |
| 1443 | AllObserversReceived(initializing_client()->rtp_receiver_observers()), |
| 1444 | kMaxWaitForFramesMs); |
| 1445 | EXPECT_TRUE_WAIT( |
| 1446 | AllObserversReceived(receiving_client()->rtp_receiver_observers()), |
| 1447 | kMaxWaitForFramesMs); |
| 1448 | } |
| 1449 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1450 | // 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] | 1451 | // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 1452 | // See issue webrtc/2378. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1453 | TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1454 | ASSERT_TRUE(CreateTestClients()); |
| 1455 | LocalP2PTest(); |
| 1456 | VerifyDtmf(); |
| 1457 | } |
| 1458 | |
| 1459 | // This test sets up a Jsep call between two parties and test that we can get a |
| 1460 | // video aspect ratio of 16:9. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1461 | TEST_F(P2PTestConductor, LocalP2PTest16To9) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1462 | ASSERT_TRUE(CreateTestClients()); |
| 1463 | FakeConstraints constraint; |
| 1464 | double requested_ratio = 640.0/360; |
| 1465 | constraint.SetMandatoryMinAspectRatio(requested_ratio); |
| 1466 | SetVideoConstraints(constraint, constraint); |
| 1467 | LocalP2PTest(); |
| 1468 | |
| 1469 | ASSERT_LE(0, initializing_client()->rendered_height()); |
| 1470 | double initiating_video_ratio = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1471 | static_cast<double>(initializing_client()->rendered_width()) / |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1472 | initializing_client()->rendered_height(); |
| 1473 | EXPECT_LE(requested_ratio, initiating_video_ratio); |
| 1474 | |
| 1475 | ASSERT_LE(0, receiving_client()->rendered_height()); |
| 1476 | double receiving_video_ratio = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1477 | static_cast<double>(receiving_client()->rendered_width()) / |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1478 | receiving_client()->rendered_height(); |
| 1479 | EXPECT_LE(requested_ratio, receiving_video_ratio); |
| 1480 | } |
| 1481 | |
| 1482 | // This test sets up a Jsep call between two parties and test that the |
| 1483 | // received video has a resolution of 1280*720. |
| 1484 | // TODO(mallinath): Enable when |
| 1485 | // http://code.google.com/p/webrtc/issues/detail?id=981 is fixed. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1486 | TEST_F(P2PTestConductor, DISABLED_LocalP2PTest1280By720) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1487 | ASSERT_TRUE(CreateTestClients()); |
| 1488 | FakeConstraints constraint; |
| 1489 | constraint.SetMandatoryMinWidth(1280); |
| 1490 | constraint.SetMandatoryMinHeight(720); |
| 1491 | SetVideoConstraints(constraint, constraint); |
| 1492 | LocalP2PTest(); |
| 1493 | VerifyRenderedSize(1280, 720); |
| 1494 | } |
| 1495 | |
| 1496 | // This test sets up a call between two endpoints that are configured to use |
| 1497 | // DTLS key agreement. As a result, DTLS is negotiated and used for transport. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1498 | TEST_F(P2PTestConductor, LocalP2PTestDtls) { |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1499 | SetupAndVerifyDtlsCall(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 1502 | // This test sets up an one-way call, with media only from initiator to |
| 1503 | // responder. |
| 1504 | TEST_F(P2PTestConductor, OneWayMediaCall) { |
| 1505 | ASSERT_TRUE(CreateTestClients()); |
| 1506 | receiving_client()->set_auto_add_stream(false); |
| 1507 | LocalP2PTest(); |
| 1508 | } |
| 1509 | |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 1510 | TEST_F(P2PTestConductor, OneWayMediaCallWithoutConstraints) { |
| 1511 | ASSERT_TRUE(CreateTestClientsThatPreferNoConstraints()); |
| 1512 | receiving_client()->set_auto_add_stream(false); |
| 1513 | LocalP2PTest(); |
| 1514 | } |
| 1515 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1516 | // This test sets up a audio call initially and then upgrades to audio/video, |
| 1517 | // using DTLS. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1518 | TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1519 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1520 | FakeConstraints setup_constraints; |
| 1521 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1522 | true); |
| 1523 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1524 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1525 | LocalP2PTest(); |
| 1526 | receiving_client()->SetReceiveAudioVideo(true, true); |
| 1527 | receiving_client()->Negotiate(); |
| 1528 | } |
| 1529 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1530 | // This test sets up a call transfer to a new caller with a different DTLS |
| 1531 | // fingerprint. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1532 | TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCallee) { |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1533 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 1534 | SetupAndVerifyDtlsCall(); |
| 1535 | |
| 1536 | // Keeping the original peer around which will still send packets to the |
| 1537 | // receiving client. These SRTP packets will be dropped. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1538 | std::unique_ptr<PeerConnectionTestClient> original_peer( |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1539 | set_initializing_client(CreateDtlsClientWithAlternateKey())); |
| 1540 | original_peer->pc()->Close(); |
| 1541 | |
| 1542 | SetSignalingReceivers(); |
| 1543 | receiving_client()->SetExpectIceRestart(true); |
| 1544 | LocalP2PTest(); |
| 1545 | VerifyRenderedSize(640, 480); |
| 1546 | } |
| 1547 | |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame] | 1548 | // This test sets up a non-bundle call and apply bundle during ICE restart. When |
| 1549 | // bundle is in effect in the restart, the channel can successfully reset its |
| 1550 | // DTLS-SRTP context. |
| 1551 | TEST_F(P2PTestConductor, LocalP2PTestDtlsBundleInIceRestart) { |
| 1552 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 1553 | FakeConstraints setup_constraints; |
| 1554 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1555 | true); |
| 1556 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1557 | receiving_client()->RemoveBundleFromReceivedSdp(true); |
| 1558 | LocalP2PTest(); |
| 1559 | VerifyRenderedSize(640, 480); |
| 1560 | |
| 1561 | initializing_client()->IceRestart(); |
| 1562 | receiving_client()->SetExpectIceRestart(true); |
| 1563 | receiving_client()->RemoveBundleFromReceivedSdp(false); |
| 1564 | LocalP2PTest(); |
| 1565 | VerifyRenderedSize(640, 480); |
| 1566 | } |
| 1567 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1568 | // This test sets up a call transfer to a new callee with a different DTLS |
| 1569 | // fingerprint. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1570 | TEST_F(P2PTestConductor, LocalP2PTestDtlsTransferCaller) { |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1571 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 1572 | SetupAndVerifyDtlsCall(); |
| 1573 | |
| 1574 | // Keeping the original peer around which will still send packets to the |
| 1575 | // receiving client. These SRTP packets will be dropped. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1576 | std::unique_ptr<PeerConnectionTestClient> original_peer( |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1577 | set_receiving_client(CreateDtlsClientWithAlternateKey())); |
| 1578 | original_peer->pc()->Close(); |
| 1579 | |
| 1580 | SetSignalingReceivers(); |
| 1581 | initializing_client()->IceRestart(); |
Taylor Brandstetter | 0a1bc53 | 2016-04-19 18:03:26 -0700 | [diff] [blame] | 1582 | LocalP2PTest(); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 1583 | VerifyRenderedSize(640, 480); |
| 1584 | } |
| 1585 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 1586 | TEST_F(P2PTestConductor, LocalP2PTestCVO) { |
| 1587 | ASSERT_TRUE(CreateTestClients()); |
| 1588 | SetCaptureRotation(webrtc::kVideoRotation_90); |
| 1589 | LocalP2PTest(); |
| 1590 | VerifyRenderedSize(640, 480, webrtc::kVideoRotation_90); |
| 1591 | } |
| 1592 | |
| 1593 | TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportCVO) { |
| 1594 | ASSERT_TRUE(CreateTestClients()); |
| 1595 | SetCaptureRotation(webrtc::kVideoRotation_90); |
| 1596 | receiving_client()->RemoveCvoFromReceivedSdp(true); |
| 1597 | LocalP2PTest(); |
| 1598 | VerifyRenderedSize(480, 640, webrtc::kVideoRotation_0); |
| 1599 | } |
| 1600 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1601 | // This test sets up a call between two endpoints that are configured to use |
| 1602 | // DTLS key agreement. The offerer don't support SDES. As a result, DTLS is |
| 1603 | // negotiated and used for transport. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1604 | TEST_F(P2PTestConductor, LocalP2PTestOfferDtlsButNotSdes) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1605 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1606 | FakeConstraints setup_constraints; |
| 1607 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1608 | true); |
| 1609 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1610 | receiving_client()->RemoveSdesCryptoFromReceivedSdp(true); |
| 1611 | LocalP2PTest(); |
| 1612 | VerifyRenderedSize(640, 480); |
| 1613 | } |
| 1614 | |
| 1615 | // This test sets up a Jsep call between two parties, and the callee only |
| 1616 | // accept to receive video. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1617 | TEST_F(P2PTestConductor, LocalP2PTestAnswerVideo) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1618 | ASSERT_TRUE(CreateTestClients()); |
| 1619 | receiving_client()->SetReceiveAudioVideo(false, true); |
| 1620 | LocalP2PTest(); |
| 1621 | } |
| 1622 | |
| 1623 | // This test sets up a Jsep call between two parties, and the callee only |
| 1624 | // accept to receive audio. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1625 | TEST_F(P2PTestConductor, LocalP2PTestAnswerAudio) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1626 | ASSERT_TRUE(CreateTestClients()); |
| 1627 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1628 | LocalP2PTest(); |
| 1629 | } |
| 1630 | |
| 1631 | // This test sets up a Jsep call between two parties, and the callee reject both |
| 1632 | // audio and video. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1633 | TEST_F(P2PTestConductor, LocalP2PTestAnswerNone) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1634 | ASSERT_TRUE(CreateTestClients()); |
| 1635 | receiving_client()->SetReceiveAudioVideo(false, false); |
| 1636 | LocalP2PTest(); |
| 1637 | } |
| 1638 | |
| 1639 | // This test sets up an audio and video call between two parties. After the call |
| 1640 | // runs for a while (10 frames), the caller sends an update offer with video |
| 1641 | // being rejected. Once the re-negotiation is done, the video flow should stop |
| 1642 | // and the audio flow should continue. |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1643 | TEST_F(P2PTestConductor, UpdateOfferWithRejectedContent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1644 | ASSERT_TRUE(CreateTestClients()); |
| 1645 | LocalP2PTest(); |
| 1646 | TestUpdateOfferWithRejectedContent(); |
| 1647 | } |
| 1648 | |
| 1649 | // This test sets up a Jsep call between two parties. The MSID is removed from |
| 1650 | // the SDP strings from the caller. |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 1651 | TEST_F(P2PTestConductor, LocalP2PTestWithoutMsid) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1652 | ASSERT_TRUE(CreateTestClients()); |
| 1653 | receiving_client()->RemoveMsidFromReceivedSdp(true); |
| 1654 | // TODO(perkj): Currently there is a bug that cause audio to stop playing if |
| 1655 | // audio and video is muxed when MSID is disabled. Remove |
| 1656 | // SetRemoveBundleFromSdp once |
| 1657 | // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed. |
| 1658 | receiving_client()->RemoveBundleFromReceivedSdp(true); |
| 1659 | LocalP2PTest(); |
| 1660 | } |
| 1661 | |
| 1662 | // This test sets up a Jsep call between two parties and the initiating peer |
| 1663 | // sends two steams. |
| 1664 | // TODO(perkj): Disabled due to |
| 1665 | // https://code.google.com/p/webrtc/issues/detail?id=1454 |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1666 | TEST_F(P2PTestConductor, DISABLED_LocalP2PTestTwoStreams) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1667 | ASSERT_TRUE(CreateTestClients()); |
| 1668 | // Set optional video constraint to max 320pixels to decrease CPU usage. |
| 1669 | FakeConstraints constraint; |
| 1670 | constraint.SetOptionalMaxWidth(320); |
| 1671 | SetVideoConstraints(constraint, constraint); |
| 1672 | initializing_client()->AddMediaStream(true, true); |
| 1673 | initializing_client()->AddMediaStream(false, true); |
| 1674 | ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams()); |
| 1675 | LocalP2PTest(); |
| 1676 | EXPECT_EQ(2u, receiving_client()->number_of_remote_streams()); |
| 1677 | } |
| 1678 | |
| 1679 | // Test that we can receive the audio output level from a remote audio track. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1680 | TEST_F(P2PTestConductor, GetAudioOutputLevelStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1681 | ASSERT_TRUE(CreateTestClients()); |
| 1682 | LocalP2PTest(); |
| 1683 | |
| 1684 | StreamCollectionInterface* remote_streams = |
| 1685 | initializing_client()->remote_streams(); |
| 1686 | ASSERT_GT(remote_streams->count(), 0u); |
| 1687 | ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1688 | MediaStreamTrackInterface* remote_audio_track = |
| 1689 | remote_streams->at(0)->GetAudioTracks()[0]; |
| 1690 | |
| 1691 | // Get the audio output level stats. Note that the level is not available |
| 1692 | // until a RTCP packet has been received. |
| 1693 | EXPECT_TRUE_WAIT( |
| 1694 | initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0, |
| 1695 | kMaxWaitForStatsMs); |
| 1696 | } |
| 1697 | |
| 1698 | // Test that an audio input level is reported. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1699 | TEST_F(P2PTestConductor, GetAudioInputLevelStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1700 | ASSERT_TRUE(CreateTestClients()); |
| 1701 | LocalP2PTest(); |
| 1702 | |
| 1703 | // Get the audio input level stats. The level should be available very |
| 1704 | // soon after the test starts. |
| 1705 | EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0, |
| 1706 | kMaxWaitForStatsMs); |
| 1707 | } |
| 1708 | |
| 1709 | // Test that we can get incoming byte counts from both audio and video tracks. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1710 | TEST_F(P2PTestConductor, GetBytesReceivedStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1711 | ASSERT_TRUE(CreateTestClients()); |
| 1712 | LocalP2PTest(); |
| 1713 | |
| 1714 | StreamCollectionInterface* remote_streams = |
| 1715 | initializing_client()->remote_streams(); |
| 1716 | ASSERT_GT(remote_streams->count(), 0u); |
| 1717 | ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1718 | MediaStreamTrackInterface* remote_audio_track = |
| 1719 | remote_streams->at(0)->GetAudioTracks()[0]; |
| 1720 | EXPECT_TRUE_WAIT( |
| 1721 | initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0, |
| 1722 | kMaxWaitForStatsMs); |
| 1723 | |
| 1724 | MediaStreamTrackInterface* remote_video_track = |
| 1725 | remote_streams->at(0)->GetVideoTracks()[0]; |
| 1726 | EXPECT_TRUE_WAIT( |
| 1727 | initializing_client()->GetBytesReceivedStats(remote_video_track) > 0, |
| 1728 | kMaxWaitForStatsMs); |
| 1729 | } |
| 1730 | |
| 1731 | // Test that we can get outgoing byte counts from both audio and video tracks. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1732 | TEST_F(P2PTestConductor, GetBytesSentStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1733 | ASSERT_TRUE(CreateTestClients()); |
| 1734 | LocalP2PTest(); |
| 1735 | |
| 1736 | StreamCollectionInterface* local_streams = |
| 1737 | initializing_client()->local_streams(); |
| 1738 | ASSERT_GT(local_streams->count(), 0u); |
| 1739 | ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1740 | MediaStreamTrackInterface* local_audio_track = |
| 1741 | local_streams->at(0)->GetAudioTracks()[0]; |
| 1742 | EXPECT_TRUE_WAIT( |
| 1743 | initializing_client()->GetBytesSentStats(local_audio_track) > 0, |
| 1744 | kMaxWaitForStatsMs); |
| 1745 | |
| 1746 | MediaStreamTrackInterface* local_video_track = |
| 1747 | local_streams->at(0)->GetVideoTracks()[0]; |
| 1748 | EXPECT_TRUE_WAIT( |
| 1749 | initializing_client()->GetBytesSentStats(local_video_track) > 0, |
| 1750 | kMaxWaitForStatsMs); |
| 1751 | } |
| 1752 | |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1753 | // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1754 | TEST_F(P2PTestConductor, GetDtls12None) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1755 | PeerConnectionFactory::Options init_options; |
| 1756 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1757 | PeerConnectionFactory::Options recv_options; |
| 1758 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1759 | ASSERT_TRUE( |
| 1760 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1761 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1762 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1763 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 1764 | LocalP2PTest(); |
| 1765 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1766 | EXPECT_TRUE_WAIT( |
| 1767 | rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1768 | initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), |
| 1769 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1770 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1771 | initializing_client()->GetSrtpCipherStats(), |
| 1772 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1773 | EXPECT_EQ(1, |
| 1774 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1775 | kDefaultSrtpCryptoSuite)); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | // Test that DTLS 1.2 is used if both ends support it. |
torbjorng | 79a5a83 | 2016-01-15 07:16:51 -0800 | [diff] [blame] | 1779 | TEST_F(P2PTestConductor, GetDtls12Both) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1780 | PeerConnectionFactory::Options init_options; |
| 1781 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1782 | PeerConnectionFactory::Options recv_options; |
| 1783 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1784 | ASSERT_TRUE( |
| 1785 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1786 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1787 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1788 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1789 | LocalP2PTest(); |
| 1790 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1791 | EXPECT_TRUE_WAIT( |
| 1792 | rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1793 | initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), |
| 1794 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1795 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1796 | initializing_client()->GetSrtpCipherStats(), |
| 1797 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1798 | EXPECT_EQ(1, |
| 1799 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1800 | kDefaultSrtpCryptoSuite)); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | // Test that DTLS 1.0 is used if the initator supports DTLS 1.2 and the |
| 1804 | // received supports 1.0. |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1805 | TEST_F(P2PTestConductor, GetDtls12Init) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1806 | PeerConnectionFactory::Options init_options; |
| 1807 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1808 | PeerConnectionFactory::Options recv_options; |
| 1809 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1810 | ASSERT_TRUE( |
| 1811 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1812 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1813 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1814 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1815 | LocalP2PTest(); |
| 1816 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1817 | EXPECT_TRUE_WAIT( |
| 1818 | rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1819 | initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), |
| 1820 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1821 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1822 | initializing_client()->GetSrtpCipherStats(), |
| 1823 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1824 | EXPECT_EQ(1, |
| 1825 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1826 | kDefaultSrtpCryptoSuite)); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | // Test that DTLS 1.0 is used if the initator supports DTLS 1.0 and the |
| 1830 | // received supports 1.2. |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1831 | TEST_F(P2PTestConductor, GetDtls12Recv) { |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1832 | PeerConnectionFactory::Options init_options; |
| 1833 | init_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1834 | PeerConnectionFactory::Options recv_options; |
| 1835 | recv_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1836 | ASSERT_TRUE( |
| 1837 | CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1838 | rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1839 | init_observer = new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1840 | initializing_client()->pc()->RegisterUMAObserver(init_observer); |
Joachim Bauch | 04e5b49 | 2015-05-29 09:40:39 +0200 | [diff] [blame] | 1841 | LocalP2PTest(); |
| 1842 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1843 | EXPECT_TRUE_WAIT( |
| 1844 | rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1845 | initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), |
| 1846 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1847 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1848 | initializing_client()->GetSrtpCipherStats(), |
| 1849 | kMaxWaitForStatsMs); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1850 | EXPECT_EQ(1, |
| 1851 | init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1852 | kDefaultSrtpCryptoSuite)); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1855 | // Test that a non-GCM cipher is used if both sides only support non-GCM. |
| 1856 | TEST_F(P2PTestConductor, GetGcmNone) { |
| 1857 | TestGcmNegotiation(false, false, kDefaultSrtpCryptoSuite); |
| 1858 | } |
| 1859 | |
| 1860 | // Test that a GCM cipher is used if both ends support it. |
| 1861 | TEST_F(P2PTestConductor, GetGcmBoth) { |
| 1862 | TestGcmNegotiation(true, true, kDefaultSrtpCryptoSuiteGcm); |
| 1863 | } |
| 1864 | |
| 1865 | // Test that GCM isn't used if only the initiator supports it. |
| 1866 | TEST_F(P2PTestConductor, GetGcmInit) { |
| 1867 | TestGcmNegotiation(true, false, kDefaultSrtpCryptoSuite); |
| 1868 | } |
| 1869 | |
| 1870 | // Test that GCM isn't used if only the receiver supports it. |
| 1871 | TEST_F(P2PTestConductor, GetGcmRecv) { |
| 1872 | TestGcmNegotiation(false, true, kDefaultSrtpCryptoSuite); |
| 1873 | } |
| 1874 | |
deadbeef | b5cb19b | 2015-11-23 16:39:12 -0800 | [diff] [blame] | 1875 | // This test sets up a call between two parties with audio, video and an RTP |
| 1876 | // data channel. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1877 | TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1878 | FakeConstraints setup_constraints; |
| 1879 | setup_constraints.SetAllowRtpDataChannels(); |
| 1880 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1881 | initializing_client()->CreateDataChannel(); |
| 1882 | LocalP2PTest(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 1883 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1884 | ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1885 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1886 | kMaxWaitMs); |
| 1887 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), |
| 1888 | kMaxWaitMs); |
| 1889 | |
| 1890 | std::string data = "hello world"; |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1891 | |
| 1892 | SendRtpData(initializing_client()->data_channel(), data); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1893 | EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), |
| 1894 | kMaxWaitMs); |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1895 | |
| 1896 | SendRtpData(receiving_client()->data_channel(), data); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1897 | EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), |
| 1898 | kMaxWaitMs); |
| 1899 | |
| 1900 | receiving_client()->data_channel()->Close(); |
| 1901 | // Send new offer and answer. |
| 1902 | receiving_client()->Negotiate(); |
| 1903 | EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); |
| 1904 | EXPECT_FALSE(receiving_client()->data_observer()->IsOpen()); |
| 1905 | } |
| 1906 | |
deadbeef | b5cb19b | 2015-11-23 16:39:12 -0800 | [diff] [blame] | 1907 | // This test sets up a call between two parties with audio, video and an SCTP |
| 1908 | // data channel. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 1909 | TEST_F(P2PTestConductor, LocalP2PTestSctpDataChannel) { |
deadbeef | b5cb19b | 2015-11-23 16:39:12 -0800 | [diff] [blame] | 1910 | ASSERT_TRUE(CreateTestClients()); |
| 1911 | initializing_client()->CreateDataChannel(); |
| 1912 | LocalP2PTest(); |
| 1913 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1914 | EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs); |
| 1915 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1916 | kMaxWaitMs); |
| 1917 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
| 1918 | |
| 1919 | std::string data = "hello world"; |
| 1920 | |
| 1921 | initializing_client()->data_channel()->Send(DataBuffer(data)); |
| 1922 | EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), |
| 1923 | kMaxWaitMs); |
| 1924 | |
| 1925 | receiving_client()->data_channel()->Send(DataBuffer(data)); |
| 1926 | EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), |
| 1927 | kMaxWaitMs); |
| 1928 | |
| 1929 | receiving_client()->data_channel()->Close(); |
deadbeef | 1588793 | 2015-12-14 19:32:34 -0800 | [diff] [blame] | 1930 | EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(), |
| 1931 | kMaxWaitMs); |
| 1932 | EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
deadbeef | b5cb19b | 2015-11-23 16:39:12 -0800 | [diff] [blame] | 1933 | } |
| 1934 | |
Taylor Brandstetter | 9b5306c | 2016-08-18 11:40:37 -0700 | [diff] [blame^] | 1935 | TEST_F(P2PTestConductor, UnorderedSctpDataChannel) { |
| 1936 | ASSERT_TRUE(CreateTestClients()); |
| 1937 | webrtc::DataChannelInit init; |
| 1938 | init.ordered = false; |
| 1939 | initializing_client()->CreateDataChannel(&init); |
| 1940 | |
| 1941 | // Introduce random network delays. |
| 1942 | // Otherwise it's not a true "unordered" test. |
| 1943 | virtual_socket_server()->set_delay_mean(20); |
| 1944 | virtual_socket_server()->set_delay_stddev(5); |
| 1945 | virtual_socket_server()->UpdateDelayDistribution(); |
| 1946 | |
| 1947 | initializing_client()->Negotiate(); |
| 1948 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1949 | EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs); |
| 1950 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1951 | kMaxWaitMs); |
| 1952 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
| 1953 | |
| 1954 | static constexpr int kNumMessages = 100; |
| 1955 | // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 1956 | static constexpr size_t kMaxMessageSize = 4096; |
| 1957 | // Create and send random messages. |
| 1958 | std::vector<std::string> sent_messages; |
| 1959 | for (int i = 0; i < kNumMessages; ++i) { |
| 1960 | size_t length = (rand() % kMaxMessageSize) + 1; |
| 1961 | std::string message; |
| 1962 | ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 1963 | initializing_client()->data_channel()->Send(DataBuffer(message)); |
| 1964 | receiving_client()->data_channel()->Send(DataBuffer(message)); |
| 1965 | sent_messages.push_back(message); |
| 1966 | } |
| 1967 | |
| 1968 | EXPECT_EQ_WAIT( |
| 1969 | kNumMessages, |
| 1970 | initializing_client()->data_observer()->received_message_count(), |
| 1971 | kMaxWaitMs); |
| 1972 | EXPECT_EQ_WAIT(kNumMessages, |
| 1973 | receiving_client()->data_observer()->received_message_count(), |
| 1974 | kMaxWaitMs); |
| 1975 | |
| 1976 | // Sort and compare to make sure none of the messages were corrupted. |
| 1977 | std::vector<std::string> initializing_client_received_messages = |
| 1978 | initializing_client()->data_observer()->messages(); |
| 1979 | std::vector<std::string> receiving_client_received_messages = |
| 1980 | receiving_client()->data_observer()->messages(); |
| 1981 | std::sort(sent_messages.begin(), sent_messages.end()); |
| 1982 | std::sort(initializing_client_received_messages.begin(), |
| 1983 | initializing_client_received_messages.end()); |
| 1984 | std::sort(receiving_client_received_messages.begin(), |
| 1985 | receiving_client_received_messages.end()); |
| 1986 | EXPECT_EQ(sent_messages, initializing_client_received_messages); |
| 1987 | EXPECT_EQ(sent_messages, receiving_client_received_messages); |
| 1988 | |
| 1989 | receiving_client()->data_channel()->Close(); |
| 1990 | EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(), |
| 1991 | kMaxWaitMs); |
| 1992 | EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
| 1993 | } |
| 1994 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1995 | // This test sets up a call between two parties and creates a data channel. |
| 1996 | // The test tests that received data is buffered unless an observer has been |
| 1997 | // registered. |
| 1998 | // Rtp data channels can receive data before the underlying |
| 1999 | // transport has detected that a channel is writable and thus data can be |
| 2000 | // received before the data channel state changes to open. That is hard to test |
| 2001 | // but the same buffering is used in that case. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2002 | TEST_F(P2PTestConductor, RegisterDataChannelObserver) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2003 | FakeConstraints setup_constraints; |
| 2004 | setup_constraints.SetAllowRtpDataChannels(); |
| 2005 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 2006 | initializing_client()->CreateDataChannel(); |
| 2007 | initializing_client()->Negotiate(); |
| 2008 | |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 2009 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 2010 | ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2011 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 2012 | kMaxWaitMs); |
| 2013 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, |
| 2014 | receiving_client()->data_channel()->state(), kMaxWaitMs); |
| 2015 | |
| 2016 | // Unregister the existing observer. |
| 2017 | receiving_client()->data_channel()->UnregisterObserver(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2018 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2019 | std::string data = "hello world"; |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 2020 | SendRtpData(initializing_client()->data_channel(), data); |
| 2021 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2022 | // Wait a while to allow the sent data to arrive before an observer is |
| 2023 | // registered.. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2024 | rtc::Thread::Current()->ProcessMessages(100); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2025 | |
| 2026 | MockDataChannelObserver new_observer(receiving_client()->data_channel()); |
| 2027 | EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs); |
| 2028 | } |
| 2029 | |
| 2030 | // This test sets up a call between two parties with audio, video and but only |
| 2031 | // the initiating client support data. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2032 | TEST_F(P2PTestConductor, LocalP2PTestReceiverDoesntSupportData) { |
buildbot@webrtc.org | 61c1b8e | 2014-04-09 06:06:38 +0000 | [diff] [blame] | 2033 | FakeConstraints setup_constraints_1; |
| 2034 | setup_constraints_1.SetAllowRtpDataChannels(); |
| 2035 | // Must disable DTLS to make negotiation succeed. |
| 2036 | setup_constraints_1.SetMandatory( |
| 2037 | MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 2038 | FakeConstraints setup_constraints_2; |
| 2039 | setup_constraints_2.SetMandatory( |
| 2040 | MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 2041 | ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2042 | initializing_client()->CreateDataChannel(); |
| 2043 | LocalP2PTest(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 2044 | EXPECT_TRUE(initializing_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2045 | EXPECT_FALSE(receiving_client()->data_channel()); |
| 2046 | EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); |
| 2047 | } |
| 2048 | |
| 2049 | // This test sets up a call between two parties with audio, video. When audio |
| 2050 | // and video is setup and flowing and data channel is negotiated. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2051 | TEST_F(P2PTestConductor, AddDataChannelAfterRenegotiation) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2052 | FakeConstraints setup_constraints; |
| 2053 | setup_constraints.SetAllowRtpDataChannels(); |
| 2054 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 2055 | LocalP2PTest(); |
| 2056 | initializing_client()->CreateDataChannel(); |
| 2057 | // Send new offer and answer. |
| 2058 | initializing_client()->Negotiate(); |
deadbeef | af1b59c | 2015-10-15 12:08:41 -0700 | [diff] [blame] | 2059 | ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 2060 | ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2061 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 2062 | kMaxWaitMs); |
| 2063 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), |
| 2064 | kMaxWaitMs); |
| 2065 | } |
| 2066 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2067 | // This test sets up a Jsep call with SCTP DataChannel and verifies the |
| 2068 | // negotiation is completed without error. |
| 2069 | #ifdef HAVE_SCTP |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2070 | TEST_F(P2PTestConductor, CreateOfferWithSctpDataChannel) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2071 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 2072 | FakeConstraints constraints; |
| 2073 | constraints.SetMandatory( |
| 2074 | MediaConstraintsInterface::kEnableDtlsSrtp, true); |
| 2075 | ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); |
| 2076 | initializing_client()->CreateDataChannel(); |
| 2077 | initializing_client()->Negotiate(false, false); |
| 2078 | } |
| 2079 | #endif |
| 2080 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2081 | // This test sets up a call between two parties with audio, and video. |
| 2082 | // During the call, the initializing side restart ice and the test verifies that |
| 2083 | // new ice candidates are generated and audio and video still can flow. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2084 | TEST_F(P2PTestConductor, IceRestart) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2085 | ASSERT_TRUE(CreateTestClients()); |
| 2086 | |
| 2087 | // Negotiate and wait for ice completion and make sure audio and video plays. |
| 2088 | LocalP2PTest(); |
| 2089 | |
| 2090 | // Create a SDP string of the first audio candidate for both clients. |
| 2091 | const webrtc::IceCandidateCollection* audio_candidates_initiator = |
| 2092 | initializing_client()->pc()->local_description()->candidates(0); |
| 2093 | const webrtc::IceCandidateCollection* audio_candidates_receiver = |
| 2094 | receiving_client()->pc()->local_description()->candidates(0); |
| 2095 | ASSERT_GT(audio_candidates_initiator->count(), 0u); |
| 2096 | ASSERT_GT(audio_candidates_receiver->count(), 0u); |
| 2097 | std::string initiator_candidate; |
| 2098 | EXPECT_TRUE( |
| 2099 | audio_candidates_initiator->at(0)->ToString(&initiator_candidate)); |
| 2100 | std::string receiver_candidate; |
| 2101 | EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate)); |
| 2102 | |
| 2103 | // Restart ice on the initializing client. |
| 2104 | receiving_client()->SetExpectIceRestart(true); |
| 2105 | initializing_client()->IceRestart(); |
| 2106 | |
| 2107 | // Negotiate and wait for ice completion again and make sure audio and video |
| 2108 | // plays. |
| 2109 | LocalP2PTest(); |
| 2110 | |
| 2111 | // Create a SDP string of the first audio candidate for both clients again. |
| 2112 | const webrtc::IceCandidateCollection* audio_candidates_initiator_restart = |
| 2113 | initializing_client()->pc()->local_description()->candidates(0); |
| 2114 | const webrtc::IceCandidateCollection* audio_candidates_reciever_restart = |
| 2115 | receiving_client()->pc()->local_description()->candidates(0); |
| 2116 | ASSERT_GT(audio_candidates_initiator_restart->count(), 0u); |
| 2117 | ASSERT_GT(audio_candidates_reciever_restart->count(), 0u); |
| 2118 | std::string initiator_candidate_restart; |
| 2119 | EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString( |
| 2120 | &initiator_candidate_restart)); |
| 2121 | std::string receiver_candidate_restart; |
| 2122 | EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString( |
| 2123 | &receiver_candidate_restart)); |
| 2124 | |
| 2125 | // Verify that the first candidates in the local session descriptions has |
| 2126 | // changed. |
| 2127 | EXPECT_NE(initiator_candidate, initiator_candidate_restart); |
| 2128 | EXPECT_NE(receiver_candidate, receiver_candidate_restart); |
| 2129 | } |
| 2130 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 2131 | // This test sets up a call between two parties with audio, and video. |
| 2132 | // It then renegotiates setting the video m-line to "port 0", then later |
| 2133 | // renegotiates again, enabling video. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2134 | TEST_F(P2PTestConductor, LocalP2PTestVideoDisableEnable) { |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 2135 | ASSERT_TRUE(CreateTestClients()); |
| 2136 | |
| 2137 | // Do initial negotiation. Will result in video and audio sendonly m-lines. |
| 2138 | receiving_client()->set_auto_add_stream(false); |
| 2139 | initializing_client()->AddMediaStream(true, true); |
| 2140 | initializing_client()->Negotiate(); |
| 2141 | |
| 2142 | // Negotiate again, disabling the video m-line (receiving client will |
| 2143 | // set port to 0 due to mandatory "OfferToReceiveVideo: false" constraint). |
| 2144 | receiving_client()->SetReceiveVideo(false); |
| 2145 | initializing_client()->Negotiate(); |
| 2146 | |
| 2147 | // Enable video and do negotiation again, making sure video is received |
| 2148 | // end-to-end. |
| 2149 | receiving_client()->SetReceiveVideo(true); |
| 2150 | receiving_client()->AddMediaStream(true, true); |
| 2151 | LocalP2PTest(); |
| 2152 | } |
| 2153 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2154 | // This test sets up a Jsep call between two parties with external |
| 2155 | // VideoDecoderFactory. |
stefan@webrtc.org | da79008 | 2013-09-17 13:11:38 +0000 | [diff] [blame] | 2156 | // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 2157 | // See issue webrtc/2378. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2158 | TEST_F(P2PTestConductor, DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2159 | ASSERT_TRUE(CreateTestClients()); |
| 2160 | EnableVideoDecoderFactory(); |
| 2161 | LocalP2PTest(); |
| 2162 | } |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2163 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2164 | // This tests that if we negotiate after calling CreateSender but before we |
| 2165 | // have a track, then set a track later, frames from the newly-set track are |
| 2166 | // received end-to-end. |
deadbeef | 7c73bdb | 2015-12-10 15:10:44 -0800 | [diff] [blame] | 2167 | TEST_F(P2PTestConductor, EarlyWarmupTest) { |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2168 | ASSERT_TRUE(CreateTestClients()); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 2169 | auto audio_sender = |
| 2170 | initializing_client()->pc()->CreateSender("audio", "stream_id"); |
| 2171 | auto video_sender = |
| 2172 | initializing_client()->pc()->CreateSender("video", "stream_id"); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2173 | initializing_client()->Negotiate(); |
| 2174 | // Wait for ICE connection to complete, without any tracks. |
| 2175 | // Note that the receiving client WILL (in HandleIncomingOffer) create |
| 2176 | // tracks, so it's only the initiator here that's doing early warmup. |
| 2177 | ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 2178 | VerifySessionDescriptions(); |
| 2179 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2180 | initializing_client()->ice_connection_state(), |
| 2181 | kMaxWaitForFramesMs); |
| 2182 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2183 | receiving_client()->ice_connection_state(), |
| 2184 | kMaxWaitForFramesMs); |
| 2185 | // Now set the tracks, and expect frames to immediately start flowing. |
| 2186 | EXPECT_TRUE( |
| 2187 | audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); |
| 2188 | EXPECT_TRUE( |
| 2189 | video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 2190 | EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount), |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2191 | kMaxWaitForFramesMs); |
| 2192 | } |
| 2193 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2194 | #ifdef HAVE_QUIC |
| 2195 | // This test sets up a call between two parties using QUIC instead of DTLS for |
| 2196 | // audio and video, and a QUIC data channel. |
| 2197 | TEST_F(P2PTestConductor, LocalP2PTestQuicDataChannel) { |
| 2198 | config()->enable_quic = true; |
| 2199 | ASSERT_TRUE(CreateTestClients()); |
| 2200 | webrtc::DataChannelInit init; |
| 2201 | init.ordered = false; |
| 2202 | init.reliable = true; |
| 2203 | init.id = 1; |
| 2204 | initializing_client()->CreateDataChannel(&init); |
| 2205 | receiving_client()->CreateDataChannel(&init); |
| 2206 | LocalP2PTest(); |
| 2207 | ASSERT_NE(nullptr, initializing_client()->data_channel()); |
| 2208 | ASSERT_NE(nullptr, receiving_client()->data_channel()); |
| 2209 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 2210 | kMaxWaitMs); |
| 2211 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
| 2212 | |
| 2213 | std::string data = "hello world"; |
| 2214 | |
| 2215 | initializing_client()->data_channel()->Send(DataBuffer(data)); |
| 2216 | EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), |
| 2217 | kMaxWaitMs); |
| 2218 | |
| 2219 | receiving_client()->data_channel()->Send(DataBuffer(data)); |
| 2220 | EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), |
| 2221 | kMaxWaitMs); |
| 2222 | } |
| 2223 | |
| 2224 | // Tests that negotiation of QUIC data channels is completed without error. |
| 2225 | TEST_F(P2PTestConductor, NegotiateQuicDataChannel) { |
| 2226 | config()->enable_quic = true; |
| 2227 | FakeConstraints constraints; |
| 2228 | constraints.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); |
| 2229 | ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); |
| 2230 | webrtc::DataChannelInit init; |
| 2231 | init.ordered = false; |
| 2232 | init.reliable = true; |
| 2233 | init.id = 1; |
| 2234 | initializing_client()->CreateDataChannel(&init); |
| 2235 | initializing_client()->Negotiate(false, false); |
| 2236 | } |
| 2237 | |
| 2238 | // This test sets up a JSEP call using QUIC. The callee only receives video. |
| 2239 | TEST_F(P2PTestConductor, LocalP2PTestVideoOnlyWithQuic) { |
| 2240 | config()->enable_quic = true; |
| 2241 | ASSERT_TRUE(CreateTestClients()); |
| 2242 | receiving_client()->SetReceiveAudioVideo(false, true); |
| 2243 | LocalP2PTest(); |
| 2244 | } |
| 2245 | |
| 2246 | // This test sets up a JSEP call using QUIC. The callee only receives audio. |
| 2247 | TEST_F(P2PTestConductor, LocalP2PTestAudioOnlyWithQuic) { |
| 2248 | config()->enable_quic = true; |
| 2249 | ASSERT_TRUE(CreateTestClients()); |
| 2250 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 2251 | LocalP2PTest(); |
| 2252 | } |
| 2253 | |
| 2254 | // This test sets up a JSEP call using QUIC. The callee rejects both audio and |
| 2255 | // video. |
| 2256 | TEST_F(P2PTestConductor, LocalP2PTestNoVideoAudioWithQuic) { |
| 2257 | config()->enable_quic = true; |
| 2258 | ASSERT_TRUE(CreateTestClients()); |
| 2259 | receiving_client()->SetReceiveAudioVideo(false, false); |
| 2260 | LocalP2PTest(); |
| 2261 | } |
| 2262 | |
| 2263 | #endif // HAVE_QUIC |
| 2264 | |
nisse | d98cf1f | 2016-04-22 07:27:36 -0700 | [diff] [blame] | 2265 | TEST_F(P2PTestConductor, ForwardVideoOnlyStream) { |
| 2266 | ASSERT_TRUE(CreateTestClients()); |
| 2267 | // One-way stream |
| 2268 | receiving_client()->set_auto_add_stream(false); |
| 2269 | // Video only, audio forwarding not expected to work. |
| 2270 | initializing_client()->AddMediaStream(false, true); |
| 2271 | initializing_client()->Negotiate(); |
| 2272 | |
| 2273 | ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 2274 | VerifySessionDescriptions(); |
| 2275 | |
| 2276 | ASSERT_TRUE(initializing_client()->can_receive_video()); |
| 2277 | ASSERT_TRUE(receiving_client()->can_receive_video()); |
| 2278 | |
| 2279 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2280 | initializing_client()->ice_connection_state(), |
| 2281 | kMaxWaitForFramesMs); |
| 2282 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2283 | receiving_client()->ice_connection_state(), |
| 2284 | kMaxWaitForFramesMs); |
| 2285 | |
| 2286 | ASSERT_TRUE(receiving_client()->remote_streams()->count() == 1); |
| 2287 | |
| 2288 | // Echo the stream back. |
| 2289 | receiving_client()->pc()->AddStream( |
| 2290 | receiving_client()->remote_streams()->at(0)); |
| 2291 | receiving_client()->Negotiate(); |
| 2292 | |
| 2293 | EXPECT_TRUE_WAIT( |
| 2294 | initializing_client()->VideoFramesReceivedCheck(kEndVideoFrameCount), |
| 2295 | kMaxWaitForFramesMs); |
| 2296 | } |
| 2297 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2298 | class IceServerParsingTest : public testing::Test { |
| 2299 | public: |
| 2300 | // Convenience for parsing a single URL. |
| 2301 | bool ParseUrl(const std::string& url) { |
| 2302 | return ParseUrl(url, std::string(), std::string()); |
| 2303 | } |
| 2304 | |
| 2305 | bool ParseUrl(const std::string& url, |
| 2306 | const std::string& username, |
| 2307 | const std::string& password) { |
| 2308 | PeerConnectionInterface::IceServers servers; |
| 2309 | PeerConnectionInterface::IceServer server; |
| 2310 | server.urls.push_back(url); |
| 2311 | server.username = username; |
| 2312 | server.password = password; |
| 2313 | servers.push_back(server); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2314 | return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | protected: |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2318 | cricket::ServerAddresses stun_servers_; |
| 2319 | std::vector<cricket::RelayServerConfig> turn_servers_; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2320 | }; |
| 2321 | |
| 2322 | // Make sure all STUN/TURN prefixes are parsed correctly. |
| 2323 | TEST_F(IceServerParsingTest, ParseStunPrefixes) { |
| 2324 | EXPECT_TRUE(ParseUrl("stun:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2325 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2326 | EXPECT_EQ(0U, turn_servers_.size()); |
| 2327 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2328 | |
| 2329 | EXPECT_TRUE(ParseUrl("stuns:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2330 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2331 | EXPECT_EQ(0U, turn_servers_.size()); |
| 2332 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2333 | |
| 2334 | EXPECT_TRUE(ParseUrl("turn:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2335 | EXPECT_EQ(0U, stun_servers_.size()); |
| 2336 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2337 | EXPECT_FALSE(turn_servers_[0].ports[0].secure); |
| 2338 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2339 | |
| 2340 | EXPECT_TRUE(ParseUrl("turns:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2341 | EXPECT_EQ(0U, stun_servers_.size()); |
| 2342 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2343 | EXPECT_TRUE(turn_servers_[0].ports[0].secure); |
| 2344 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2345 | |
| 2346 | // invalid prefixes |
| 2347 | EXPECT_FALSE(ParseUrl("stunn:hostname")); |
| 2348 | EXPECT_FALSE(ParseUrl(":hostname")); |
| 2349 | EXPECT_FALSE(ParseUrl(":")); |
| 2350 | EXPECT_FALSE(ParseUrl("")); |
| 2351 | } |
| 2352 | |
| 2353 | TEST_F(IceServerParsingTest, VerifyDefaults) { |
| 2354 | // TURNS defaults |
| 2355 | EXPECT_TRUE(ParseUrl("turns:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2356 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2357 | EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port()); |
| 2358 | EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); |
| 2359 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2360 | |
| 2361 | // TURN defaults |
| 2362 | EXPECT_TRUE(ParseUrl("turn:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2363 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2364 | EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port()); |
| 2365 | EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); |
| 2366 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2367 | |
| 2368 | // STUN defaults |
| 2369 | EXPECT_TRUE(ParseUrl("stun:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2370 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2371 | EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 2372 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port |
| 2376 | // can be parsed correctly. |
| 2377 | TEST_F(IceServerParsingTest, ParseHostnameAndPort) { |
| 2378 | EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2379 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2380 | EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); |
| 2381 | EXPECT_EQ(1234, stun_servers_.begin()->port()); |
| 2382 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2383 | |
| 2384 | EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2385 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2386 | EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); |
| 2387 | EXPECT_EQ(4321, stun_servers_.begin()->port()); |
| 2388 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2389 | |
| 2390 | EXPECT_TRUE(ParseUrl("stun:hostname:9999")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2391 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2392 | EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); |
| 2393 | EXPECT_EQ(9999, stun_servers_.begin()->port()); |
| 2394 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2395 | |
| 2396 | EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2397 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2398 | EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); |
| 2399 | EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 2400 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2401 | |
| 2402 | EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2403 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2404 | EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); |
| 2405 | EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 2406 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2407 | |
| 2408 | EXPECT_TRUE(ParseUrl("stun:hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2409 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2410 | EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); |
| 2411 | EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 2412 | stun_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2413 | |
| 2414 | // Try some invalid hostname:port strings. |
| 2415 | EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); |
| 2416 | EXPECT_FALSE(ParseUrl("stun:hostname:-1")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2417 | EXPECT_FALSE(ParseUrl("stun:hostname:port:more")); |
| 2418 | EXPECT_FALSE(ParseUrl("stun:hostname:port more")); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2419 | EXPECT_FALSE(ParseUrl("stun:hostname:")); |
| 2420 | EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); |
| 2421 | EXPECT_FALSE(ParseUrl("stun::5555")); |
| 2422 | EXPECT_FALSE(ParseUrl("stun:")); |
| 2423 | } |
| 2424 | |
| 2425 | // Test parsing the "?transport=xxx" part of the URL. |
| 2426 | TEST_F(IceServerParsingTest, ParseTransport) { |
| 2427 | EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2428 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2429 | EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); |
| 2430 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2431 | |
| 2432 | EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2433 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2434 | EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); |
| 2435 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2436 | |
| 2437 | EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); |
| 2438 | } |
| 2439 | |
| 2440 | // Test parsing ICE username contained in URL. |
| 2441 | TEST_F(IceServerParsingTest, ParseUsername) { |
| 2442 | EXPECT_TRUE(ParseUrl("turn:user@hostname")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2443 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2444 | EXPECT_EQ("user", turn_servers_[0].credentials.username); |
| 2445 | turn_servers_.clear(); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2446 | |
| 2447 | EXPECT_FALSE(ParseUrl("turn:@hostname")); |
| 2448 | EXPECT_FALSE(ParseUrl("turn:username@")); |
| 2449 | EXPECT_FALSE(ParseUrl("turn:@")); |
| 2450 | EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); |
| 2451 | } |
| 2452 | |
| 2453 | // Test that username and password from IceServer is copied into the resulting |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2454 | // RelayServerConfig. |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2455 | TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { |
| 2456 | EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2457 | EXPECT_EQ(1U, turn_servers_.size()); |
| 2458 | EXPECT_EQ("username", turn_servers_[0].credentials.username); |
| 2459 | EXPECT_EQ("password", turn_servers_[0].credentials.password); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | // Ensure that if a server has multiple URLs, each one is parsed. |
| 2463 | TEST_F(IceServerParsingTest, ParseMultipleUrls) { |
| 2464 | PeerConnectionInterface::IceServers servers; |
| 2465 | PeerConnectionInterface::IceServer server; |
| 2466 | server.urls.push_back("stun:hostname"); |
| 2467 | server.urls.push_back("turn:hostname"); |
| 2468 | servers.push_back(server); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2469 | EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
| 2470 | EXPECT_EQ(1U, stun_servers_.size()); |
| 2471 | EXPECT_EQ(1U, turn_servers_.size()); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Taylor Brandstetter | 893505d | 2016-01-07 15:12:48 -0800 | [diff] [blame] | 2474 | // Ensure that TURN servers are given unique priorities, |
| 2475 | // so that their resulting candidates have unique priorities. |
| 2476 | TEST_F(IceServerParsingTest, TurnServerPrioritiesUnique) { |
| 2477 | PeerConnectionInterface::IceServers servers; |
| 2478 | PeerConnectionInterface::IceServer server; |
| 2479 | server.urls.push_back("turn:hostname"); |
| 2480 | server.urls.push_back("turn:hostname2"); |
| 2481 | servers.push_back(server); |
| 2482 | EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
| 2483 | EXPECT_EQ(2U, turn_servers_.size()); |
| 2484 | EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
| 2485 | } |
| 2486 | |
kjellander@webrtc.org | d1cfa71 | 2013-10-16 16:51:52 +0000 | [diff] [blame] | 2487 | #endif // if !defined(THREAD_SANITIZER) |
hta | 6b4f839 | 2016-03-10 00:24:31 -0800 | [diff] [blame] | 2488 | |
| 2489 | } // namespace |