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