henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 28 | #include <vector> |
| 29 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | #include "talk/app/webrtc/audiotrack.h" |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 31 | #include "talk/app/webrtc/fakemetricsobserver.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | #include "talk/app/webrtc/jsepicecandidate.h" |
| 33 | #include "talk/app/webrtc/jsepsessiondescription.h" |
| 34 | #include "talk/app/webrtc/mediastreamsignaling.h" |
| 35 | #include "talk/app/webrtc/streamcollection.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | #include "talk/app/webrtc/test/fakeconstraints.h" |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 37 | #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 38 | #include "talk/app/webrtc/test/fakemediastreamsignaling.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 39 | #include "talk/app/webrtc/videotrack.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | #include "talk/app/webrtc/webrtcsession.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 41 | #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 42 | #include "talk/media/base/fakemediaengine.h" |
| 43 | #include "talk/media/base/fakevideorenderer.h" |
| 44 | #include "talk/media/base/mediachannel.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 45 | #include "webrtc/p2p/base/stunserver.h" |
| 46 | #include "webrtc/p2p/base/teststunserver.h" |
| 47 | #include "webrtc/p2p/base/testturnserver.h" |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 48 | #include "webrtc/p2p/base/transportchannel.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 49 | #include "webrtc/p2p/client/basicportallocator.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 50 | #include "talk/session/media/channelmanager.h" |
| 51 | #include "talk/session/media/mediasession.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | #include "webrtc/base/fakenetwork.h" |
| 53 | #include "webrtc/base/firewallsocketserver.h" |
| 54 | #include "webrtc/base/gunit.h" |
| 55 | #include "webrtc/base/logging.h" |
| 56 | #include "webrtc/base/network.h" |
| 57 | #include "webrtc/base/physicalsocketserver.h" |
| 58 | #include "webrtc/base/ssladapter.h" |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 59 | #include "webrtc/base/sslidentity.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 60 | #include "webrtc/base/sslstreamadapter.h" |
| 61 | #include "webrtc/base/stringutils.h" |
| 62 | #include "webrtc/base/thread.h" |
| 63 | #include "webrtc/base/virtualsocketserver.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | |
| 65 | #define MAYBE_SKIP_TEST(feature) \ |
| 66 | if (!(feature())) { \ |
| 67 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 68 | return; \ |
| 69 | } |
| 70 | |
| 71 | using cricket::BaseSession; |
| 72 | using cricket::DF_PLAY; |
| 73 | using cricket::DF_SEND; |
| 74 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | using cricket::TransportInfo; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 76 | using rtc::SocketAddress; |
| 77 | using rtc::scoped_ptr; |
| 78 | using rtc::Thread; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | using webrtc::CreateSessionDescription; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 80 | using webrtc::CreateSessionDescriptionObserver; |
| 81 | using webrtc::CreateSessionDescriptionRequest; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 82 | using webrtc::DtlsIdentityStoreInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | using webrtc::FakeConstraints; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 84 | using webrtc::FakeMetricsObserver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | using webrtc::IceCandidateCollection; |
| 86 | using webrtc::JsepIceCandidate; |
| 87 | using webrtc::JsepSessionDescription; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 88 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | using webrtc::PeerConnectionInterface; |
| 90 | using webrtc::SessionDescriptionInterface; |
| 91 | using webrtc::StreamCollection; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 92 | using webrtc::WebRtcSession; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 93 | using webrtc::kBundleWithoutRtcpMux; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 94 | using webrtc::kCreateChannelFailed; |
| 95 | using webrtc::kInvalidSdp; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | using webrtc::kMlineMismatch; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 97 | using webrtc::kPushDownTDFailed; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 98 | using webrtc::kSdpWithoutIceUfragPwd; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 99 | using webrtc::kSdpWithoutDtlsFingerprint; |
| 100 | using webrtc::kSdpWithoutSdesCrypto; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | using webrtc::kSessionError; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 102 | using webrtc::kSessionErrorDesc; |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 103 | using webrtc::kMaxUnsignalledRecvStreams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 105 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 106 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 107 | static const int kClientAddrPort = 0; |
| 108 | static const char kClientAddrHost1[] = "11.11.11.11"; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 109 | static const char kClientIPv6AddrHost1[] = |
| 110 | "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 111 | static const char kClientAddrHost2[] = "22.22.22.22"; |
| 112 | static const char kStunAddrHost[] = "99.99.99.1"; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 113 | static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); |
| 114 | static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 115 | static const char kTurnUsername[] = "test"; |
| 116 | static const char kTurnPassword[] = "test"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | |
| 118 | static const char kSessionVersion[] = "1"; |
| 119 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | // Media index of candidates belonging to the first media content. |
| 121 | static const int kMediaContentIndex0 = 0; |
| 122 | static const char kMediaContentName0[] = "audio"; |
| 123 | |
| 124 | // Media index of candidates belonging to the second media content. |
| 125 | static const int kMediaContentIndex1 = 1; |
| 126 | static const char kMediaContentName1[] = "video"; |
| 127 | |
| 128 | static const int kIceCandidatesTimeout = 10000; |
| 129 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 130 | static const char kFakeDtlsFingerprint[] = |
| 131 | "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:" |
| 132 | "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24"; |
| 133 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 134 | static const char kTooLongIceUfragPwd[] = |
| 135 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 136 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 137 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 138 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"; |
| 139 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 140 | static const char kSdpWithRtx[] = |
| 141 | "v=0\r\n" |
| 142 | "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n" |
| 143 | "s=-\r\n" |
| 144 | "t=0 0\r\n" |
| 145 | "a=msid-semantic: WMS stream1\r\n" |
| 146 | "m=video 9 RTP/SAVPF 0 96\r\n" |
| 147 | "c=IN IP4 0.0.0.0\r\n" |
| 148 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 149 | "a=ice-ufrag:CerjGp19G7wpXwl7\r\n" |
| 150 | "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n" |
| 151 | "a=mid:video\r\n" |
| 152 | "a=sendrecv\r\n" |
| 153 | "a=rtcp-mux\r\n" |
| 154 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 155 | "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n" |
| 156 | "a=rtpmap:0 fake_video_codec/90000\r\n" |
| 157 | "a=rtpmap:96 rtx/90000\r\n" |
| 158 | "a=fmtp:96 apt=0\r\n"; |
| 159 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 160 | enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; |
| 161 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 162 | // Add some extra |newlines| to the |message| after |line|. |
| 163 | static void InjectAfter(const std::string& line, |
| 164 | const std::string& newlines, |
| 165 | std::string* message) { |
| 166 | const std::string tmp = line + newlines; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 167 | rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(), |
| 168 | message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | class MockIceObserver : public webrtc::IceObserver { |
| 172 | public: |
| 173 | MockIceObserver() |
| 174 | : oncandidatesready_(false), |
| 175 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 176 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 177 | } |
| 178 | |
| 179 | virtual void OnIceConnectionChange( |
| 180 | PeerConnectionInterface::IceConnectionState new_state) { |
| 181 | ice_connection_state_ = new_state; |
| 182 | } |
| 183 | virtual void OnIceGatheringChange( |
| 184 | PeerConnectionInterface::IceGatheringState new_state) { |
| 185 | // We can never transition back to "new". |
| 186 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 187 | ice_gathering_state_ = new_state; |
| 188 | |
| 189 | // oncandidatesready_ really means "ICE gathering is complete". |
| 190 | // This if statement ensures that this value remains correct when we |
| 191 | // transition from kIceGatheringComplete to kIceGatheringGathering. |
| 192 | if (new_state == PeerConnectionInterface::kIceGatheringGathering) { |
| 193 | oncandidatesready_ = false; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Found a new candidate. |
| 198 | virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 199 | switch (candidate->sdp_mline_index()) { |
| 200 | case kMediaContentIndex0: |
| 201 | mline_0_candidates_.push_back(candidate->candidate()); |
| 202 | break; |
| 203 | case kMediaContentIndex1: |
| 204 | mline_1_candidates_.push_back(candidate->candidate()); |
| 205 | break; |
| 206 | default: |
| 207 | ASSERT(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 209 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | // The ICE gathering state should always be Gathering when a candidate is |
| 211 | // received (or possibly Completed in the case of the final candidate). |
| 212 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 213 | } |
| 214 | |
| 215 | // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange. |
| 216 | virtual void OnIceComplete() { |
| 217 | EXPECT_FALSE(oncandidatesready_); |
| 218 | oncandidatesready_ = true; |
| 219 | |
| 220 | // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should |
| 221 | // be called approximately simultaneously. For ease of testing, this |
| 222 | // check additionally requires that they be called in the above order. |
| 223 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, |
| 224 | ice_gathering_state_); |
| 225 | } |
| 226 | |
| 227 | bool oncandidatesready_; |
| 228 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 229 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 230 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 231 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
| 232 | }; |
| 233 | |
| 234 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 235 | public: |
| 236 | WebRtcSessionForTest(cricket::ChannelManager* cmgr, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 237 | rtc::Thread* signaling_thread, |
| 238 | rtc::Thread* worker_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 239 | cricket::PortAllocator* port_allocator, |
| 240 | webrtc::IceObserver* ice_observer, |
| 241 | webrtc::MediaStreamSignaling* mediastream_signaling) |
| 242 | : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator, |
| 243 | mediastream_signaling) { |
| 244 | RegisterIceObserver(ice_observer); |
| 245 | } |
| 246 | virtual ~WebRtcSessionForTest() {} |
| 247 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 248 | // Note that these methods are only safe to use if the signaling thread |
| 249 | // is the same as the worker thread |
| 250 | cricket::TransportChannel* voice_rtp_transport_channel() { |
| 251 | return rtp_transport_channel(voice_channel()); |
| 252 | } |
| 253 | |
| 254 | cricket::TransportChannel* voice_rtcp_transport_channel() { |
| 255 | return rtcp_transport_channel(voice_channel()); |
| 256 | } |
| 257 | |
| 258 | cricket::TransportChannel* video_rtp_transport_channel() { |
| 259 | return rtp_transport_channel(video_channel()); |
| 260 | } |
| 261 | |
| 262 | cricket::TransportChannel* video_rtcp_transport_channel() { |
| 263 | return rtcp_transport_channel(video_channel()); |
| 264 | } |
| 265 | |
| 266 | cricket::TransportChannel* data_rtp_transport_channel() { |
| 267 | return rtp_transport_channel(data_channel()); |
| 268 | } |
| 269 | |
| 270 | cricket::TransportChannel* data_rtcp_transport_channel() { |
| 271 | return rtcp_transport_channel(data_channel()); |
| 272 | } |
| 273 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | using webrtc::WebRtcSession::SetAudioPlayout; |
| 275 | using webrtc::WebRtcSession::SetAudioSend; |
| 276 | using webrtc::WebRtcSession::SetCaptureDevice; |
| 277 | using webrtc::WebRtcSession::SetVideoPlayout; |
| 278 | using webrtc::WebRtcSession::SetVideoSend; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 279 | |
| 280 | private: |
| 281 | cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) { |
| 282 | if (!ch) { |
| 283 | return nullptr; |
| 284 | } |
| 285 | return ch->transport_channel(); |
| 286 | } |
| 287 | |
| 288 | cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) { |
| 289 | if (!ch) { |
| 290 | return nullptr; |
| 291 | } |
| 292 | return ch->rtcp_transport_channel(); |
| 293 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 294 | }; |
| 295 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 296 | class WebRtcSessionCreateSDPObserverForTest |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 297 | : public rtc::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 298 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 299 | enum State { |
| 300 | kInit, |
| 301 | kFailed, |
| 302 | kSucceeded, |
| 303 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 304 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 305 | |
| 306 | // CreateSessionDescriptionObserver implementation. |
| 307 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 308 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 309 | state_ = kSucceeded; |
| 310 | } |
| 311 | virtual void OnFailure(const std::string& error) { |
| 312 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 313 | } |
| 314 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 315 | SessionDescriptionInterface* description() { return description_.get(); } |
| 316 | |
| 317 | SessionDescriptionInterface* ReleaseDescription() { |
| 318 | return description_.release(); |
| 319 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 321 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 322 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 323 | protected: |
| 324 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | |
| 326 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 327 | rtc::scoped_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 328 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 329 | }; |
| 330 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 331 | class FakeAudioRenderer : public cricket::AudioRenderer { |
| 332 | public: |
solenberg | 98c6886 | 2015-10-09 03:27:14 -0700 | [diff] [blame] | 333 | FakeAudioRenderer() : sink_(NULL) {} |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 334 | virtual ~FakeAudioRenderer() { |
| 335 | if (sink_) |
| 336 | sink_->OnClose(); |
| 337 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 338 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 339 | void SetSink(Sink* sink) override { sink_ = sink; } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 340 | |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 341 | cricket::AudioRenderer::Sink* sink() const { return sink_; } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 342 | private: |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 343 | cricket::AudioRenderer::Sink* sink_; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 344 | }; |
| 345 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 346 | class WebRtcSessionTest |
| 347 | : public testing::TestWithParam<RTCCertificateGenerationMethod> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 348 | protected: |
| 349 | // TODO Investigate why ChannelManager crashes, if it's created |
| 350 | // after stun_server. |
| 351 | WebRtcSessionTest() |
| 352 | : media_engine_(new cricket::FakeMediaEngine()), |
| 353 | data_engine_(new cricket::FakeDataEngine()), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | channel_manager_(new cricket::ChannelManager( |
solenberg | facbbec | 2015-09-24 00:41:50 -0700 | [diff] [blame] | 355 | media_engine_, data_engine_, new cricket::CaptureManager(), |
| 356 | rtc::Thread::Current())), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 357 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 358 | desc_factory_(new cricket::MediaSessionDescriptionFactory( |
| 359 | channel_manager_.get(), tdesc_factory_.get())), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 360 | pss_(new rtc::PhysicalSocketServer), |
| 361 | vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 362 | fss_(new rtc::FirewallSocketServer(vss_.get())), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 363 | ss_scope_(fss_.get()), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 364 | stun_socket_addr_(rtc::SocketAddress(kStunAddrHost, |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 365 | cricket::STUN_SERVER_PORT)), |
jiayl@webrtc.org | bebc75e | 2014-09-26 23:01:11 +0000 | [diff] [blame] | 366 | stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 367 | stun_socket_addr_)), |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 368 | turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 369 | mediastream_signaling_(channel_manager_.get()), |
| 370 | metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 371 | cricket::ServerAddresses stun_servers; |
| 372 | stun_servers.insert(stun_socket_addr_); |
| 373 | allocator_.reset(new cricket::BasicPortAllocator( |
| 374 | &network_manager_, |
| 375 | stun_servers, |
| 376 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 377 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 378 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 379 | EXPECT_TRUE(channel_manager_->Init()); |
| 380 | desc_factory_->set_add_legacy_streams(false); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 381 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void AddInterface(const SocketAddress& addr) { |
| 385 | network_manager_.AddInterface(addr); |
| 386 | } |
| 387 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 388 | // If |dtls_identity_store| != null or |rtc_configuration| contains |
| 389 | // |certificates| then DTLS will be enabled unless explicitly disabled by |
| 390 | // |rtc_configuration| options. When DTLS is enabled a certificate will be |
| 391 | // used if provided, otherwise one will be generated using the |
| 392 | // |dtls_identity_store|. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 393 | void Init( |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 394 | rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 395 | const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 396 | ASSERT_TRUE(session_.get() == NULL); |
| 397 | session_.reset(new WebRtcSessionForTest( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 398 | channel_manager_.get(), rtc::Thread::Current(), |
| 399 | rtc::Thread::Current(), allocator_.get(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | &observer_, |
| 401 | &mediastream_signaling_)); |
| 402 | |
| 403 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 404 | observer_.ice_connection_state_); |
| 405 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 406 | observer_.ice_gathering_state_); |
| 407 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 408 | EXPECT_TRUE(session_->Initialize(options_, constraints_.get(), |
| 409 | dtls_identity_store.Pass(), |
| 410 | rtc_configuration)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 411 | session_->set_metrics_observer(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | } |
| 413 | |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 414 | void Init() { |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 415 | PeerConnectionInterface::RTCConfiguration configuration; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 416 | Init(nullptr, configuration); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void InitWithIceTransport( |
| 420 | PeerConnectionInterface::IceTransportsType ice_transport_type) { |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 421 | PeerConnectionInterface::RTCConfiguration configuration; |
| 422 | configuration.type = ice_transport_type; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 423 | Init(nullptr, configuration); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | void InitWithBundlePolicy( |
| 427 | PeerConnectionInterface::BundlePolicy bundle_policy) { |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 428 | PeerConnectionInterface::RTCConfiguration configuration; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 429 | configuration.bundle_policy = bundle_policy; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 430 | Init(nullptr, configuration); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void InitWithRtcpMuxPolicy( |
| 434 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 435 | PeerConnectionInterface::RTCConfiguration configuration; |
| 436 | configuration.rtcp_mux_policy = rtcp_mux_policy; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 437 | Init(nullptr, configuration); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 440 | // Successfully init with DTLS; with a certificate generated and supplied or |
| 441 | // with a store that generates it for us. |
| 442 | void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
| 443 | rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store; |
| 444 | PeerConnectionInterface::RTCConfiguration configuration; |
| 445 | if (cert_gen_method == ALREADY_GENERATED) { |
| 446 | configuration.certificates.push_back( |
| 447 | FakeDtlsIdentityStore::GenerateCertificate()); |
| 448 | } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
| 449 | dtls_identity_store.reset(new FakeDtlsIdentityStore()); |
| 450 | dtls_identity_store->set_should_fail(false); |
| 451 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 452 | RTC_CHECK(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 453 | } |
| 454 | Init(dtls_identity_store.Pass(), configuration); |
| 455 | } |
| 456 | |
| 457 | // Init with DTLS with a store that will fail to generate a certificate. |
| 458 | void InitWithDtlsIdentityGenFail() { |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 459 | rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| 460 | new FakeDtlsIdentityStore()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 461 | dtls_identity_store->set_should_fail(true); |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 462 | PeerConnectionInterface::RTCConfiguration configuration; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 463 | Init(dtls_identity_store.Pass(), configuration); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 464 | } |
| 465 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 466 | void InitWithDtmfCodec() { |
| 467 | // Add kTelephoneEventCodec for dtmf test. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 468 | const cricket::AudioCodec kTelephoneEventCodec( |
| 469 | 106, "telephone-event", 8000, 0, 1, 0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 470 | std::vector<cricket::AudioCodec> codecs; |
| 471 | codecs.push_back(kTelephoneEventCodec); |
| 472 | media_engine_->SetAudioCodecs(codecs); |
| 473 | desc_factory_->set_audio_codecs(codecs); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 474 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | // Creates a local offer and applies it. Starts ice. |
| 478 | // Call mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 479 | // to decide which streams to create. |
| 480 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 481 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 482 | SetLocalDescriptionWithoutError(offer); |
| 483 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 484 | observer_.ice_gathering_state_, |
| 485 | kIceCandidatesTimeout); |
| 486 | } |
| 487 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 488 | SessionDescriptionInterface* CreateOffer() { |
| 489 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 490 | options.offer_to_receive_audio = |
| 491 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 492 | |
| 493 | return CreateOffer(options); |
| 494 | } |
| 495 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 496 | SessionDescriptionInterface* CreateOffer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 497 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 498 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 499 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 500 | session_->CreateOffer(observer, options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 501 | EXPECT_TRUE_WAIT( |
| 502 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 503 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 504 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | SessionDescriptionInterface* CreateAnswer( |
| 508 | const webrtc::MediaConstraintsInterface* constraints) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 509 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 510 | = new WebRtcSessionCreateSDPObserverForTest(); |
| 511 | session_->CreateAnswer(observer, constraints); |
| 512 | EXPECT_TRUE_WAIT( |
| 513 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 514 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 515 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 516 | } |
| 517 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 518 | bool ChannelsExist() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 519 | return (session_->voice_channel() != NULL && |
| 520 | session_->video_channel() != NULL); |
| 521 | } |
| 522 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 523 | void VerifyCryptoParams(const cricket::SessionDescription* sdp) { |
| 524 | ASSERT_TRUE(session_.get() != NULL); |
| 525 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 526 | ASSERT_TRUE(content != NULL); |
| 527 | const cricket::AudioContentDescription* audio_content = |
| 528 | static_cast<const cricket::AudioContentDescription*>( |
| 529 | content->description); |
| 530 | ASSERT_TRUE(audio_content != NULL); |
| 531 | ASSERT_EQ(1U, audio_content->cryptos().size()); |
| 532 | ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); |
| 533 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 534 | audio_content->cryptos()[0].cipher_suite); |
| 535 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 536 | audio_content->protocol()); |
| 537 | |
| 538 | content = cricket::GetFirstVideoContent(sdp); |
| 539 | ASSERT_TRUE(content != NULL); |
| 540 | const cricket::VideoContentDescription* video_content = |
| 541 | static_cast<const cricket::VideoContentDescription*>( |
| 542 | content->description); |
| 543 | ASSERT_TRUE(video_content != NULL); |
| 544 | ASSERT_EQ(1U, video_content->cryptos().size()); |
| 545 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 546 | video_content->cryptos()[0].cipher_suite); |
| 547 | ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); |
| 548 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 549 | video_content->protocol()); |
| 550 | } |
| 551 | |
| 552 | void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { |
| 553 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 554 | ASSERT_TRUE(content != NULL); |
| 555 | const cricket::AudioContentDescription* audio_content = |
| 556 | static_cast<const cricket::AudioContentDescription*>( |
| 557 | content->description); |
| 558 | ASSERT_TRUE(audio_content != NULL); |
| 559 | ASSERT_EQ(0U, audio_content->cryptos().size()); |
| 560 | |
| 561 | content = cricket::GetFirstVideoContent(sdp); |
| 562 | ASSERT_TRUE(content != NULL); |
| 563 | const cricket::VideoContentDescription* video_content = |
| 564 | static_cast<const cricket::VideoContentDescription*>( |
| 565 | content->description); |
| 566 | ASSERT_TRUE(video_content != NULL); |
| 567 | ASSERT_EQ(0U, video_content->cryptos().size()); |
| 568 | |
| 569 | if (dtls) { |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 570 | EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 571 | audio_content->protocol()); |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 572 | EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 573 | video_content->protocol()); |
| 574 | } else { |
| 575 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 576 | audio_content->protocol()); |
| 577 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 578 | video_content->protocol()); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | // Set the internal fake description factories to do DTLS-SRTP. |
| 583 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 584 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 585 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 586 | rtc::ToString(rtc::CreateRandomId()); |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 587 | // Confirmed to work with KT_RSA and KT_ECDSA. |
Henrik Boström | 3a14bf3 | 2015-08-31 09:27:58 +0200 | [diff] [blame] | 588 | tdesc_factory_->set_certificate(rtc::RTCCertificate::Create( |
torbjorng | 335204c | 2015-10-08 02:30:14 -0700 | [diff] [blame] | 589 | rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate( |
| 590 | identity_name, rtc::KT_DEFAULT)).Pass())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 592 | } |
| 593 | |
| 594 | void VerifyFingerprintStatus(const cricket::SessionDescription* sdp, |
| 595 | bool expected) { |
| 596 | const TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 597 | ASSERT_TRUE(audio != NULL); |
| 598 | ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 599 | const TransportInfo* video = sdp->GetTransportInfoByName("video"); |
| 600 | ASSERT_TRUE(video != NULL); |
| 601 | ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void VerifyAnswerFromNonCryptoOffer() { |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 605 | // Create an SDP without Crypto. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 607 | options.recv_video = true; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 608 | JsepSessionDescription* offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 609 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 610 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 611 | VerifyNoCryptoParams(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 612 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
| 613 | offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 614 | const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 615 | // Answer should be NULL as no crypto params in offer. |
| 616 | ASSERT_TRUE(answer == NULL); |
| 617 | } |
| 618 | |
| 619 | void VerifyAnswerFromCryptoOffer() { |
| 620 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 621 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | options.bundle_enabled = true; |
| 623 | scoped_ptr<JsepSessionDescription> offer( |
| 624 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 625 | ASSERT_TRUE(offer.get() != NULL); |
| 626 | VerifyCryptoParams(offer->description()); |
| 627 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 628 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 629 | ASSERT_TRUE(answer.get() != NULL); |
| 630 | VerifyCryptoParams(answer->description()); |
| 631 | } |
| 632 | |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 633 | void SetAndVerifyNumUnsignalledRecvStreams( |
| 634 | int value_set, int value_expected) { |
| 635 | constraints_.reset(new FakeConstraints()); |
| 636 | constraints_->AddOptional( |
| 637 | webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams, |
| 638 | value_set); |
| 639 | session_.reset(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 640 | Init(); |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 641 | mediastream_signaling_.SendAudioVideoStream1(); |
| 642 | SessionDescriptionInterface* offer = CreateOffer(); |
| 643 | |
| 644 | SetLocalDescriptionWithoutError(offer); |
| 645 | |
| 646 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 647 | |
| 648 | ASSERT_TRUE(video_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 649 | const cricket::VideoOptions& video_options = video_channel_->options(); |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 650 | EXPECT_EQ(value_expected, |
| 651 | video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1)); |
| 652 | } |
| 653 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1, |
| 655 | const cricket::SessionDescription* desc2, |
| 656 | bool expect_equal) { |
| 657 | if (desc1->contents().size() != desc2->contents().size()) { |
| 658 | EXPECT_FALSE(expect_equal); |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | const cricket::ContentInfos& contents = desc1->contents(); |
| 663 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 664 | |
| 665 | for (; it != contents.end(); ++it) { |
| 666 | const cricket::TransportDescription* transport_desc1 = |
| 667 | desc1->GetTransportDescriptionByName(it->name); |
| 668 | const cricket::TransportDescription* transport_desc2 = |
| 669 | desc2->GetTransportDescriptionByName(it->name); |
| 670 | if (!transport_desc1 || !transport_desc2) { |
| 671 | EXPECT_FALSE(expect_equal); |
| 672 | return; |
| 673 | } |
| 674 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 675 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 676 | EXPECT_FALSE(expect_equal); |
| 677 | return; |
| 678 | } |
| 679 | } |
| 680 | EXPECT_TRUE(expect_equal); |
| 681 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 682 | |
| 683 | void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 684 | std::string *sdp) { |
| 685 | const cricket::SessionDescription* desc = current_desc->description(); |
| 686 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 687 | |
| 688 | const cricket::ContentInfos& contents = desc->contents(); |
| 689 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 690 | // Replace ufrag and pwd lines with empty strings. |
| 691 | for (; it != contents.end(); ++it) { |
| 692 | const cricket::TransportDescription* transport_desc = |
| 693 | desc->GetTransportDescriptionByName(it->name); |
| 694 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 695 | + "\r\n"; |
| 696 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 697 | + "\r\n"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 698 | rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 699 | "", 0, |
| 700 | sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 701 | rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 702 | "", 0, |
| 703 | sdp); |
| 704 | } |
| 705 | } |
| 706 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 707 | void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 708 | const std::string& modified_ice_ufrag, |
| 709 | const std::string& modified_ice_pwd, |
| 710 | std::string* sdp) { |
| 711 | const cricket::SessionDescription* desc = current_desc->description(); |
| 712 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 713 | |
| 714 | const cricket::ContentInfos& contents = desc->contents(); |
| 715 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 716 | // Replace ufrag and pwd lines with |modified_ice_ufrag| and |
| 717 | // |modified_ice_pwd| strings. |
| 718 | for (; it != contents.end(); ++it) { |
| 719 | const cricket::TransportDescription* transport_desc = |
| 720 | desc->GetTransportDescriptionByName(it->name); |
| 721 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 722 | + "\r\n"; |
| 723 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 724 | + "\r\n"; |
| 725 | std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n"; |
| 726 | std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 727 | rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 728 | mod_ufrag.c_str(), mod_ufrag.length(), |
| 729 | sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 730 | rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 731 | mod_pwd.c_str(), mod_pwd.length(), |
| 732 | sdp); |
| 733 | } |
| 734 | } |
| 735 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 736 | // Creates a remote offer and and applies it as a remote description, |
| 737 | // creates a local answer and applies is as a local description. |
| 738 | // Call mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 739 | // to decide which local and remote streams to create. |
| 740 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 741 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 742 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 743 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 744 | SetLocalDescriptionWithoutError(answer); |
| 745 | } |
| 746 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 747 | EXPECT_TRUE(session_->SetLocalDescription(desc, NULL)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 748 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | } |
| 750 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
| 751 | BaseSession::State expected_state) { |
| 752 | SetLocalDescriptionWithoutError(desc); |
| 753 | EXPECT_EQ(expected_state, session_->state()); |
| 754 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 755 | void SetLocalDescriptionExpectError(const std::string& action, |
| 756 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 757 | SessionDescriptionInterface* desc) { |
| 758 | std::string error; |
| 759 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 760 | std::string sdp_type = "local "; |
| 761 | sdp_type.append(action); |
| 762 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 764 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 765 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 766 | SessionDescriptionInterface* desc) { |
| 767 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 768 | expected_error, desc); |
| 769 | } |
| 770 | void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, |
| 771 | SessionDescriptionInterface* desc) { |
| 772 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 773 | expected_error, desc); |
| 774 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 775 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 776 | EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL)); |
| 777 | } |
| 778 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
| 779 | BaseSession::State expected_state) { |
| 780 | SetRemoteDescriptionWithoutError(desc); |
| 781 | EXPECT_EQ(expected_state, session_->state()); |
| 782 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 783 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 784 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | SessionDescriptionInterface* desc) { |
| 786 | std::string error; |
| 787 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 788 | std::string sdp_type = "remote "; |
| 789 | sdp_type.append(action); |
| 790 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 792 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 793 | void SetRemoteDescriptionOfferExpectError( |
| 794 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 795 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 796 | expected_error, desc); |
| 797 | } |
| 798 | void SetRemoteDescriptionPranswerExpectError( |
| 799 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 800 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer, |
| 801 | expected_error, desc); |
| 802 | } |
| 803 | void SetRemoteDescriptionAnswerExpectError( |
| 804 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 805 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 806 | expected_error, desc); |
| 807 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 808 | |
| 809 | void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer, |
| 810 | SessionDescriptionInterface** nocrypto_answer) { |
| 811 | // Create a SDP without Crypto. |
| 812 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 813 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 814 | options.bundle_enabled = true; |
| 815 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 816 | ASSERT_TRUE(*offer != NULL); |
| 817 | VerifyCryptoParams((*offer)->description()); |
| 818 | |
| 819 | *nocrypto_answer = CreateRemoteAnswer(*offer, options, |
| 820 | cricket::SEC_DISABLED); |
| 821 | EXPECT_TRUE(*nocrypto_answer != NULL); |
| 822 | } |
| 823 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 824 | void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer, |
| 825 | SessionDescriptionInterface** nodtls_answer) { |
| 826 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 827 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 828 | options.bundle_enabled = true; |
| 829 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 830 | rtc::scoped_ptr<SessionDescriptionInterface> temp_offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 831 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
| 832 | |
| 833 | *nodtls_answer = |
| 834 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
| 835 | EXPECT_TRUE(*nodtls_answer != NULL); |
| 836 | VerifyFingerprintStatus((*nodtls_answer)->description(), false); |
| 837 | VerifyCryptoParams((*nodtls_answer)->description()); |
| 838 | |
| 839 | SetFactoryDtlsSrtp(); |
| 840 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 841 | ASSERT_TRUE(*offer != NULL); |
| 842 | VerifyFingerprintStatus((*offer)->description(), true); |
| 843 | VerifyCryptoParams((*offer)->description()); |
| 844 | } |
| 845 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 846 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 847 | cricket::MediaSessionOptions options, |
| 848 | cricket::SecurePolicy secure_policy, |
| 849 | const std::string& session_version, |
| 850 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 851 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 852 | const cricket::SessionDescription* cricket_desc = NULL; |
| 853 | if (current_desc) { |
| 854 | cricket_desc = current_desc->description(); |
| 855 | session_id = current_desc->session_id(); |
| 856 | } |
| 857 | |
| 858 | desc_factory_->set_secure(secure_policy); |
| 859 | JsepSessionDescription* offer( |
| 860 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 861 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 862 | session_id, session_version)) { |
| 863 | delete offer; |
| 864 | offer = NULL; |
| 865 | } |
| 866 | return offer; |
| 867 | } |
| 868 | JsepSessionDescription* CreateRemoteOffer( |
| 869 | cricket::MediaSessionOptions options) { |
| 870 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 871 | kSessionVersion, NULL); |
| 872 | } |
| 873 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 874 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 875 | return CreateRemoteOfferWithVersion( |
| 876 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | } |
| 878 | JsepSessionDescription* CreateRemoteOffer( |
| 879 | cricket::MediaSessionOptions options, |
| 880 | const SessionDescriptionInterface* current_desc) { |
| 881 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 882 | kSessionVersion, current_desc); |
| 883 | } |
| 884 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 885 | JsepSessionDescription* CreateRemoteOfferWithSctpPort( |
| 886 | const char* sctp_stream_name, int new_port, |
| 887 | cricket::MediaSessionOptions options) { |
| 888 | options.data_channel_type = cricket::DCT_SCTP; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 889 | options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel", |
| 890 | sctp_stream_name); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 891 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 892 | } |
| 893 | |
| 894 | // Takes ownership of offer_basis (and deletes it). |
| 895 | JsepSessionDescription* ChangeSDPSctpPort( |
| 896 | int new_port, webrtc::SessionDescriptionInterface *offer_basis) { |
| 897 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 898 | // SessionDescription from the mutated string. |
| 899 | const char* default_port_str = "5000"; |
| 900 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 901 | rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 902 | std::string offer_str; |
| 903 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 904 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 905 | new_port_str, strlen(new_port_str), |
| 906 | &offer_str); |
| 907 | JsepSessionDescription* offer = new JsepSessionDescription( |
| 908 | offer_basis->type()); |
| 909 | delete offer_basis; |
| 910 | offer->Initialize(offer_str, NULL); |
| 911 | return offer; |
| 912 | } |
| 913 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 914 | // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX() |
| 915 | // before this function to decide which streams to create. |
| 916 | JsepSessionDescription* CreateRemoteOffer() { |
| 917 | cricket::MediaSessionOptions options; |
| 918 | mediastream_signaling_.GetOptionsForAnswer(NULL, &options); |
| 919 | return CreateRemoteOffer(options, session_->remote_description()); |
| 920 | } |
| 921 | |
| 922 | JsepSessionDescription* CreateRemoteAnswer( |
| 923 | const SessionDescriptionInterface* offer, |
| 924 | cricket::MediaSessionOptions options, |
| 925 | cricket::SecurePolicy policy) { |
| 926 | desc_factory_->set_secure(policy); |
| 927 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 928 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | JsepSessionDescription* answer( |
| 930 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 931 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 932 | options, NULL), |
| 933 | session_id, kSessionVersion)) { |
| 934 | delete answer; |
| 935 | answer = NULL; |
| 936 | } |
| 937 | return answer; |
| 938 | } |
| 939 | |
| 940 | JsepSessionDescription* CreateRemoteAnswer( |
| 941 | const SessionDescriptionInterface* offer, |
| 942 | cricket::MediaSessionOptions options) { |
| 943 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 944 | } |
| 945 | |
| 946 | // Creates an answer session description with streams based on |
| 947 | // |mediastream_signaling_|. Call |
| 948 | // mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 949 | // to decide which streams to create. |
| 950 | JsepSessionDescription* CreateRemoteAnswer( |
| 951 | const SessionDescriptionInterface* offer) { |
| 952 | cricket::MediaSessionOptions options; |
| 953 | mediastream_signaling_.GetOptionsForAnswer(NULL, &options); |
| 954 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 955 | } |
| 956 | |
| 957 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 958 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 959 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 960 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 961 | |
| 962 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 963 | options.use_rtp_mux = bundle; |
| 964 | |
| 965 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 966 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 967 | // and answer. |
| 968 | SetLocalDescriptionWithoutError(offer); |
| 969 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 970 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 971 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 972 | std::string sdp; |
| 973 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 974 | |
| 975 | size_t expected_candidate_num = 2; |
| 976 | if (!rtcp_mux) { |
| 977 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 978 | // for rtp and rtcp. |
| 979 | expected_candidate_num = 4; |
| 980 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 981 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 982 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 983 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 984 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 985 | &sdp); |
| 986 | } |
| 987 | |
| 988 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 989 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 990 | |
| 991 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 992 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 993 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 994 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 995 | if (bundle) { |
| 996 | EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
| 997 | } else { |
| 998 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | // Tests that we can only send DTMF when the dtmf codec is supported. |
| 1002 | void TestCanInsertDtmf(bool can) { |
| 1003 | if (can) { |
| 1004 | InitWithDtmfCodec(); |
| 1005 | } else { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1006 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1007 | } |
| 1008 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1009 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1010 | EXPECT_FALSE(session_->CanInsertDtmf("")); |
| 1011 | EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1)); |
| 1012 | } |
| 1013 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1014 | // Helper class to configure loopback network and verify Best |
| 1015 | // Connection using right IP protocol for TestLoopbackCall |
| 1016 | // method. LoopbackNetworkManager applies firewall rules to block |
| 1017 | // all ping traffic once ICE completed, and remove them to observe |
| 1018 | // ICE reconnected again. This LoopbackNetworkConfiguration struct |
| 1019 | // verifies the best connection is using the right IP protocol after |
| 1020 | // initial ICE convergences. |
| 1021 | |
| 1022 | class LoopbackNetworkConfiguration { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1023 | public: |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1024 | LoopbackNetworkConfiguration() |
| 1025 | : test_ipv6_network_(false), |
| 1026 | test_extra_ipv4_network_(false), |
| 1027 | best_connection_after_initial_ice_converged_(1, 0) {} |
| 1028 | |
| 1029 | // Used to track the expected best connection count in each IP protocol. |
| 1030 | struct ExpectedBestConnection { |
| 1031 | ExpectedBestConnection(int ipv4_count, int ipv6_count) |
| 1032 | : ipv4_count_(ipv4_count), |
| 1033 | ipv6_count_(ipv6_count) {} |
| 1034 | |
| 1035 | int ipv4_count_; |
| 1036 | int ipv6_count_; |
| 1037 | }; |
| 1038 | |
| 1039 | bool test_ipv6_network_; |
| 1040 | bool test_extra_ipv4_network_; |
| 1041 | ExpectedBestConnection best_connection_after_initial_ice_converged_; |
| 1042 | |
| 1043 | void VerifyBestConnectionAfterIceConverge( |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1044 | const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const { |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1045 | Verify(metrics_observer, best_connection_after_initial_ice_converged_); |
| 1046 | } |
| 1047 | |
| 1048 | private: |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1049 | void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer, |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1050 | const ExpectedBestConnection& expected) const { |
| 1051 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1052 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1053 | webrtc::kBestConnections_IPv4), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1054 | expected.ipv4_count_); |
| 1055 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1056 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1057 | webrtc::kBestConnections_IPv6), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1058 | expected.ipv6_count_); |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1059 | // This is used in the loopback call so there is only single host to host |
| 1060 | // candidate pair. |
| 1061 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1062 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1063 | webrtc::kIceCandidatePairHostHost), |
Guo-wei Shieh | 3cc834a | 2015-09-04 15:52:14 -0700 | [diff] [blame] | 1064 | 0); |
| 1065 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1066 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1067 | webrtc::kIceCandidatePairHostPublicHostPublic), |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1068 | 1); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1069 | } |
| 1070 | }; |
| 1071 | |
| 1072 | class LoopbackNetworkManager { |
| 1073 | public: |
| 1074 | LoopbackNetworkManager(WebRtcSessionTest* session, |
| 1075 | const LoopbackNetworkConfiguration& config) |
| 1076 | : config_(config) { |
| 1077 | session->AddInterface( |
| 1078 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1079 | if (config_.test_extra_ipv4_network_) { |
| 1080 | session->AddInterface( |
| 1081 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1082 | } |
| 1083 | if (config_.test_ipv6_network_) { |
| 1084 | session->AddInterface( |
| 1085 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | void ApplyFirewallRules(rtc::FirewallSocketServer* fss) { |
| 1090 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1091 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1092 | if (config_.test_extra_ipv4_network_) { |
| 1093 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1094 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1095 | } |
| 1096 | if (config_.test_ipv6_network_) { |
| 1097 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1098 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); } |
| 1103 | |
| 1104 | private: |
| 1105 | LoopbackNetworkConfiguration config_; |
| 1106 | }; |
| 1107 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1108 | // The method sets up a call from the session to itself, in a loopback |
| 1109 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1110 | // disconnection, and then a permanent disconnection. |
| 1111 | // This code is placed in a method so that it can be invoked |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1112 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 1113 | // While running the call, this method also checks if the session goes through |
| 1114 | // the correct sequence of ICE states when a connection is established, |
| 1115 | // broken, and re-established. |
| 1116 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1117 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 1118 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1119 | // The Gathering state should go: New -> Gathering -> Completed. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1120 | |
| 1121 | void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { |
| 1122 | LoopbackNetworkManager loopback_network_manager(this, config); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1123 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1124 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1125 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1126 | |
| 1127 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 1128 | observer_.ice_gathering_state_); |
| 1129 | SetLocalDescriptionWithoutError(offer); |
| 1130 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 1131 | observer_.ice_connection_state_); |
| 1132 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
| 1133 | observer_.ice_gathering_state_, |
| 1134 | kIceCandidatesTimeout); |
| 1135 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1136 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 1137 | observer_.ice_gathering_state_, |
| 1138 | kIceCandidatesTimeout); |
| 1139 | |
| 1140 | std::string sdp; |
| 1141 | offer->ToString(&sdp); |
| 1142 | SessionDescriptionInterface* desc = |
jbauch | fabe2c9 | 2015-07-16 13:43:14 -0700 | [diff] [blame] | 1143 | webrtc::CreateSessionDescription( |
| 1144 | JsepSessionDescription::kAnswer, sdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1145 | ASSERT_TRUE(desc != NULL); |
| 1146 | SetRemoteDescriptionWithoutError(desc); |
| 1147 | |
| 1148 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
| 1149 | observer_.ice_connection_state_, |
| 1150 | kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1151 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1152 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 1153 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1154 | observer_.ice_connection_state_, |
| 1155 | kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1156 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1157 | config.VerifyBestConnectionAfterIceConverge(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1158 | // Adding firewall rule to block ping requests, which should cause |
| 1159 | // transport channel failure. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1160 | |
| 1161 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1162 | |
| 1163 | LOG(LS_INFO) << "Firewall Rules applied"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1164 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 1165 | observer_.ice_connection_state_, |
| 1166 | kIceCandidatesTimeout); |
| 1167 | |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1168 | metrics_observer_->Reset(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1169 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1170 | // Clearing the rules, session should move back to completed state. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1171 | loopback_network_manager.ClearRules(fss_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1172 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1173 | LOG(LS_INFO) << "Firewall Rules cleared"; |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1174 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1175 | observer_.ice_connection_state_, |
| 1176 | kIceCandidatesTimeout); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1177 | |
| 1178 | // Now we block ping requests and wait until the ICE connection transitions |
| 1179 | // to the Failed state. This will take at least 30 seconds because it must |
| 1180 | // wait for the Port to timeout. |
| 1181 | int port_timeout = 30000; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1182 | |
| 1183 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1184 | LOG(LS_INFO) << "Firewall Rules applied again"; |
jlmiller@webrtc.org | 804eb46 | 2015-02-20 02:20:03 +0000 | [diff] [blame] | 1185 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1186 | observer_.ice_connection_state_, |
| 1187 | kIceCandidatesTimeout + port_timeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1190 | void TestLoopbackCall() { |
| 1191 | LoopbackNetworkConfiguration config; |
| 1192 | TestLoopbackCall(config); |
| 1193 | } |
| 1194 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1195 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 1196 | void AddCNCodecs() { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1197 | const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0); |
| 1198 | const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0); |
| 1199 | |
| 1200 | // Add kCNCodec for dtmf test. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1201 | std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();; |
| 1202 | codecs.push_back(kCNCodec1); |
| 1203 | codecs.push_back(kCNCodec2); |
| 1204 | media_engine_->SetAudioCodecs(codecs); |
| 1205 | desc_factory_->set_audio_codecs(codecs); |
| 1206 | } |
| 1207 | |
| 1208 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 1209 | const cricket::ContentDescription* description = content->description; |
| 1210 | ASSERT(description != NULL); |
| 1211 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1212 | static_cast<const cricket::AudioContentDescription*>(description); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1213 | ASSERT(audio_content_desc != NULL); |
| 1214 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 1215 | if (audio_content_desc->codecs()[i].name == "CN") |
| 1216 | return false; |
| 1217 | } |
| 1218 | return true; |
| 1219 | } |
| 1220 | |
| 1221 | void SetLocalDescriptionWithDataChannel() { |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1222 | webrtc::InternalDataChannelInit dci; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1223 | dci.reliable = false; |
| 1224 | session_->CreateDataChannel("datachannel", &dci); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1225 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1226 | SetLocalDescriptionWithoutError(offer); |
| 1227 | } |
| 1228 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1229 | void VerifyMultipleAsyncCreateDescription( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1230 | RTCCertificateGenerationMethod cert_gen_method, |
| 1231 | CreateSessionDescriptionRequest::Type type) { |
| 1232 | InitWithDtls(cert_gen_method); |
| 1233 | VerifyMultipleAsyncCreateDescriptionAfterInit(true, type); |
| 1234 | } |
| 1235 | |
| 1236 | void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 1237 | CreateSessionDescriptionRequest::Type type) { |
| 1238 | InitWithDtlsIdentityGenFail(); |
| 1239 | VerifyMultipleAsyncCreateDescriptionAfterInit(false, type); |
| 1240 | } |
| 1241 | |
| 1242 | void VerifyMultipleAsyncCreateDescriptionAfterInit( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1243 | bool success, CreateSessionDescriptionRequest::Type type) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1244 | RTC_CHECK(session_); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1245 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1246 | if (type == CreateSessionDescriptionRequest::kAnswer) { |
| 1247 | cricket::MediaSessionOptions options; |
| 1248 | scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1249 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1250 | ASSERT_TRUE(offer.get() != NULL); |
| 1251 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1252 | } |
| 1253 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1254 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1255 | const int kNumber = 3; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1256 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1257 | observers[kNumber]; |
| 1258 | for (int i = 0; i < kNumber; ++i) { |
| 1259 | observers[i] = new WebRtcSessionCreateSDPObserverForTest(); |
| 1260 | if (type == CreateSessionDescriptionRequest::kOffer) { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1261 | session_->CreateOffer(observers[i], options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1262 | } else { |
| 1263 | session_->CreateAnswer(observers[i], NULL); |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | WebRtcSessionCreateSDPObserverForTest::State expected_state = |
| 1268 | success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded : |
| 1269 | WebRtcSessionCreateSDPObserverForTest::kFailed; |
| 1270 | |
| 1271 | for (int i = 0; i < kNumber; ++i) { |
| 1272 | EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000); |
| 1273 | if (success) { |
| 1274 | EXPECT_TRUE(observers[i]->description() != NULL); |
| 1275 | } else { |
| 1276 | EXPECT_TRUE(observers[i]->description() == NULL); |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1281 | void ConfigureAllocatorWithTurn() { |
| 1282 | cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
| 1283 | cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
| 1284 | relay_server.credentials = credentials; |
| 1285 | relay_server.ports.push_back(cricket::ProtocolAddress( |
| 1286 | kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
| 1287 | allocator_->AddRelay(relay_server); |
| 1288 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 1289 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1292 | cricket::FakeMediaEngine* media_engine_; |
| 1293 | cricket::FakeDataEngine* data_engine_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1294 | rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; |
| 1295 | rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1296 | rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
| 1297 | rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1298 | rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1299 | rtc::scoped_ptr<rtc::FirewallSocketServer> fss_; |
| 1300 | rtc::SocketServerScope ss_scope_; |
| 1301 | rtc::SocketAddress stun_socket_addr_; |
jiayl@webrtc.org | bebc75e | 2014-09-26 23:01:11 +0000 | [diff] [blame] | 1302 | rtc::scoped_ptr<cricket::TestStunServer> stun_server_; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1303 | cricket::TestTurnServer turn_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1304 | rtc::FakeNetworkManager network_manager_; |
| 1305 | rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1306 | PeerConnectionFactoryInterface::Options options_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1307 | rtc::scoped_ptr<FakeConstraints> constraints_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1308 | FakeMediaStreamSignaling mediastream_signaling_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1309 | rtc::scoped_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1310 | MockIceObserver observer_; |
| 1311 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1312 | cricket::FakeVoiceMediaChannel* voice_channel_; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1313 | rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1314 | }; |
| 1315 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1316 | TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1317 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1318 | // SDES is disabled when DTLS is on. |
| 1319 | EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1322 | TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1323 | Init(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1324 | // SDES is required if DTLS is off. |
| 1325 | EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1328 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1329 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1330 | } |
| 1331 | |
| 1332 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1333 | // with rtcp-mux and/or bundle. |
| 1334 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1335 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1336 | } |
| 1337 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1338 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1339 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1340 | } |
| 1341 | |
| 1342 | TEST_F(WebRtcSessionTest, TestMultihomeCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1343 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1344 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1345 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1346 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1347 | InitiateCall(); |
| 1348 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1349 | EXPECT_EQ(8u, observer_.mline_0_candidates_.size()); |
| 1350 | EXPECT_EQ(8u, observer_.mline_1_candidates_.size()); |
| 1351 | } |
| 1352 | |
| 1353 | TEST_F(WebRtcSessionTest, TestStunError) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1354 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1355 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1356 | fss_->AddRule(false, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1357 | rtc::FP_UDP, |
| 1358 | rtc::FD_ANY, |
| 1359 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1360 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1361 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1362 | InitiateCall(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1363 | // Since kClientAddrHost1 is blocked, not expecting stun candidates for it. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1364 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1365 | EXPECT_EQ(6u, observer_.mline_0_candidates_.size()); |
| 1366 | EXPECT_EQ(6u, observer_.mline_1_candidates_.size()); |
| 1367 | } |
| 1368 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1369 | // Test session delivers no candidates gathered when constraint set to "none". |
| 1370 | TEST_F(WebRtcSessionTest, TestIceTransportsNone) { |
| 1371 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1372 | InitWithIceTransport(PeerConnectionInterface::kNone); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1373 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1374 | InitiateCall(); |
| 1375 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1376 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 1377 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 1378 | } |
| 1379 | |
| 1380 | // Test session delivers only relay candidates gathered when constaint set to |
| 1381 | // "relay". |
| 1382 | TEST_F(WebRtcSessionTest, TestIceTransportsRelay) { |
| 1383 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1384 | ConfigureAllocatorWithTurn(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1385 | InitWithIceTransport(PeerConnectionInterface::kRelay); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1386 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1387 | InitiateCall(); |
| 1388 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1389 | EXPECT_EQ(2u, observer_.mline_0_candidates_.size()); |
| 1390 | EXPECT_EQ(2u, observer_.mline_1_candidates_.size()); |
| 1391 | for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) { |
| 1392 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 1393 | observer_.mline_0_candidates_[i].type()); |
| 1394 | } |
| 1395 | for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) { |
| 1396 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 1397 | observer_.mline_1_candidates_[i].type()); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | // Test session delivers all candidates gathered when constaint set to "all". |
| 1402 | TEST_F(WebRtcSessionTest, TestIceTransportsAll) { |
| 1403 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1404 | InitWithIceTransport(PeerConnectionInterface::kAll); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1405 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1406 | InitiateCall(); |
| 1407 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1408 | // Host + STUN. By default allocator is disabled to gather relay candidates. |
| 1409 | EXPECT_EQ(4u, observer_.mline_0_candidates_.size()); |
| 1410 | EXPECT_EQ(4u, observer_.mline_1_candidates_.size()); |
| 1411 | } |
| 1412 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1413 | TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1414 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1415 | SessionDescriptionInterface* offer = NULL; |
| 1416 | // Since |offer| is NULL, there's no way to tell if it's an offer or answer. |
| 1417 | std::string unknown_action; |
| 1418 | SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1419 | SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1420 | } |
| 1421 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1422 | // Test creating offers and receive answers and make sure the |
| 1423 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1424 | TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1425 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1426 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1427 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1428 | const std::string session_id_orig = offer->session_id(); |
| 1429 | const std::string session_version_orig = offer->session_version(); |
| 1430 | SetLocalDescriptionWithoutError(offer); |
| 1431 | |
| 1432 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1433 | SessionDescriptionInterface* answer = |
| 1434 | CreateRemoteAnswer(session_->local_description()); |
| 1435 | SetRemoteDescriptionWithoutError(answer); |
| 1436 | |
| 1437 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1438 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1439 | |
| 1440 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1441 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1442 | |
| 1443 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1444 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1445 | |
| 1446 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1447 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1448 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1449 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1450 | |
| 1451 | // Create new offer without send streams. |
| 1452 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1453 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1454 | |
| 1455 | // Verify the session id is the same and the session version is |
| 1456 | // increased. |
| 1457 | EXPECT_EQ(session_id_orig, offer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1458 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1459 | rtc::FromString<uint64_t>(offer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1460 | |
| 1461 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1462 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1463 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1464 | |
| 1465 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1466 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1467 | SetRemoteDescriptionWithoutError(answer); |
| 1468 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1469 | // Make sure the receive streams have not changed. |
| 1470 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1471 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1472 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1473 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1474 | } |
| 1475 | |
| 1476 | // Test receiving offers and creating answers and make sure the |
| 1477 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1478 | TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1479 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1480 | mediastream_signaling_.SendAudioVideoStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1481 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1482 | VerifyCryptoParams(offer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1483 | SetRemoteDescriptionWithoutError(offer); |
| 1484 | |
| 1485 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1486 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1487 | VerifyCryptoParams(answer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1488 | SetLocalDescriptionWithoutError(answer); |
| 1489 | |
| 1490 | const std::string session_id_orig = answer->session_id(); |
| 1491 | const std::string session_version_orig = answer->session_version(); |
| 1492 | |
| 1493 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1494 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1495 | |
| 1496 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1497 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1498 | |
| 1499 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1500 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1501 | |
| 1502 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1503 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1504 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1505 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1506 | |
| 1507 | mediastream_signaling_.SendAudioVideoStream1And2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1508 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1509 | SetRemoteDescriptionWithoutError(offer); |
| 1510 | |
| 1511 | // Answer by turning off all send streams. |
| 1512 | mediastream_signaling_.SendNothing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1513 | answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1514 | |
| 1515 | // Verify the session id is the same and the session version is |
| 1516 | // increased. |
| 1517 | EXPECT_EQ(session_id_orig, answer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1518 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1519 | rtc::FromString<uint64_t>(answer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1520 | SetLocalDescriptionWithoutError(answer); |
| 1521 | |
| 1522 | ASSERT_EQ(2u, video_channel_->recv_streams().size()); |
| 1523 | EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id); |
| 1524 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id); |
| 1525 | ASSERT_EQ(2u, voice_channel_->recv_streams().size()); |
| 1526 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id); |
| 1527 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id); |
| 1528 | |
| 1529 | // Make sure we have no send streams. |
| 1530 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1531 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1532 | } |
| 1533 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1534 | TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1535 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1536 | media_engine_->set_fail_create_channel(true); |
| 1537 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1538 | SessionDescriptionInterface* offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1539 | ASSERT_TRUE(offer != NULL); |
| 1540 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1541 | // the offer. |
| 1542 | SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1543 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1544 | ASSERT_TRUE(offer != NULL); |
| 1545 | SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer); |
| 1546 | } |
| 1547 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1548 | // |
| 1549 | // Tests for creating/setting SDP under different SDES/DTLS polices: |
| 1550 | // |
| 1551 | // --DTLS off and SDES on |
| 1552 | // TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer: |
| 1553 | // set local/remote offer/answer with crypto --> success |
| 1554 | // TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto ---> |
| 1555 | // failure |
| 1556 | // TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto --> |
| 1557 | // failure |
| 1558 | // TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto --> |
| 1559 | // failure |
| 1560 | // |
| 1561 | // --DTLS on and SDES off |
| 1562 | // TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer: |
| 1563 | // set local/remote offer/answer with DTLS fingerprint --> success |
| 1564 | // TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS |
| 1565 | // fingerprint --> failure |
| 1566 | // TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint |
| 1567 | // --> failure |
| 1568 | // TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint |
| 1569 | // --> failure |
| 1570 | // |
| 1571 | // --Encryption disabled: DTLS off and SDES off |
| 1572 | // TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote |
| 1573 | // answer without SDES or DTLS --> success |
| 1574 | // TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local |
| 1575 | // answer without SDES or DTLS --> success |
| 1576 | // |
| 1577 | |
| 1578 | // Test that we return a failure when applying a remote/local offer that doesn't |
| 1579 | // have cryptos enabled when DTLS is off. |
| 1580 | TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1581 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1582 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1583 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1584 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1585 | options, cricket::SEC_DISABLED); |
| 1586 | ASSERT_TRUE(offer != NULL); |
| 1587 | VerifyNoCryptoParams(offer->description(), false); |
| 1588 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1589 | // the offer. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1590 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1591 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1592 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1593 | SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1596 | // Test that we return a failure when applying a local answer that doesn't have |
| 1597 | // cryptos enabled when DTLS is off. |
| 1598 | TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1599 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1600 | SessionDescriptionInterface* offer = NULL; |
| 1601 | SessionDescriptionInterface* answer = NULL; |
| 1602 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1603 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1604 | // the offer. |
| 1605 | SetRemoteDescriptionWithoutError(offer); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1606 | SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1609 | // Test we will return fail when apply an remote answer that doesn't have |
| 1610 | // crypto enabled when DTLS is off. |
| 1611 | TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1612 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1613 | SessionDescriptionInterface* offer = NULL; |
| 1614 | SessionDescriptionInterface* answer = NULL; |
| 1615 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1616 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1617 | // the offer. |
| 1618 | SetLocalDescriptionWithoutError(offer); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1619 | SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1622 | // Test that we accept an offer with a DTLS fingerprint when DTLS is on |
| 1623 | // and that we return an answer with a DTLS fingerprint. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1624 | TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1625 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1626 | mediastream_signaling_.SendAudioVideoStream1(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1627 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1628 | SetFactoryDtlsSrtp(); |
| 1629 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1630 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1631 | JsepSessionDescription* offer = |
| 1632 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1633 | ASSERT_TRUE(offer != NULL); |
| 1634 | VerifyFingerprintStatus(offer->description(), true); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1635 | VerifyNoCryptoParams(offer->description(), true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1636 | |
| 1637 | // SetRemoteDescription will take the ownership of the offer. |
| 1638 | SetRemoteDescriptionWithoutError(offer); |
| 1639 | |
| 1640 | // Verify that we get a crypto fingerprint in the answer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1641 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1642 | ASSERT_TRUE(answer != NULL); |
| 1643 | VerifyFingerprintStatus(answer->description(), true); |
| 1644 | // Check that we don't have an a=crypto line in the answer. |
| 1645 | VerifyNoCryptoParams(answer->description(), true); |
| 1646 | |
| 1647 | // Now set the local description, which should work, even without a=crypto. |
| 1648 | SetLocalDescriptionWithoutError(answer); |
| 1649 | } |
| 1650 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1651 | // Test that we set a local offer with a DTLS fingerprint when DTLS is on |
| 1652 | // and then we accept a remote answer with a DTLS fingerprint successfully. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1653 | TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1654 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1655 | mediastream_signaling_.SendAudioVideoStream1(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1656 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1657 | SetFactoryDtlsSrtp(); |
| 1658 | |
| 1659 | // Verify that we get a crypto fingerprint in the answer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1660 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1661 | ASSERT_TRUE(offer != NULL); |
| 1662 | VerifyFingerprintStatus(offer->description(), true); |
| 1663 | // Check that we don't have an a=crypto line in the offer. |
| 1664 | VerifyNoCryptoParams(offer->description(), true); |
| 1665 | |
| 1666 | // Now set the local description, which should work, even without a=crypto. |
| 1667 | SetLocalDescriptionWithoutError(offer); |
| 1668 | |
| 1669 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1670 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1671 | JsepSessionDescription* answer = |
| 1672 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1673 | ASSERT_TRUE(answer != NULL); |
| 1674 | VerifyFingerprintStatus(answer->description(), true); |
| 1675 | VerifyNoCryptoParams(answer->description(), true); |
| 1676 | |
| 1677 | // SetRemoteDescription will take the ownership of the answer. |
| 1678 | SetRemoteDescriptionWithoutError(answer); |
| 1679 | } |
| 1680 | |
| 1681 | // Test that if we support DTLS and the other side didn't offer a fingerprint, |
| 1682 | // we will fail to set the remote description. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1683 | TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1684 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1685 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1686 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1687 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1688 | options.bundle_enabled = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1689 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1690 | options, cricket::SEC_REQUIRED); |
| 1691 | ASSERT_TRUE(offer != NULL); |
| 1692 | VerifyFingerprintStatus(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1693 | VerifyCryptoParams(offer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1694 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1695 | // SetRemoteDescription will take the ownership of the offer. |
| 1696 | SetRemoteDescriptionOfferExpectError( |
| 1697 | kSdpWithoutDtlsFingerprint, offer); |
| 1698 | |
| 1699 | offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED); |
| 1700 | // SetLocalDescription will take the ownership of the offer. |
| 1701 | SetLocalDescriptionOfferExpectError( |
| 1702 | kSdpWithoutDtlsFingerprint, offer); |
| 1703 | } |
| 1704 | |
| 1705 | // Test that we return a failure when applying a local answer that doesn't have |
| 1706 | // a DTLS fingerprint when DTLS is required. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1707 | TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1708 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1709 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1710 | SessionDescriptionInterface* offer = NULL; |
| 1711 | SessionDescriptionInterface* answer = NULL; |
| 1712 | CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer); |
| 1713 | |
| 1714 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1715 | // the offer and answer. |
| 1716 | SetRemoteDescriptionWithoutError(offer); |
| 1717 | SetLocalDescriptionAnswerExpectError( |
| 1718 | kSdpWithoutDtlsFingerprint, answer); |
| 1719 | } |
| 1720 | |
| 1721 | // Test that we return a failure when applying a remote answer that doesn't have |
| 1722 | // a DTLS fingerprint when DTLS is required. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1723 | TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1724 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1725 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1726 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1727 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1728 | options.recv_video = true; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1729 | rtc::scoped_ptr<SessionDescriptionInterface> temp_offer( |
| 1730 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1731 | JsepSessionDescription* answer = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1732 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1733 | |
| 1734 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1735 | // the offer and answer. |
| 1736 | SetLocalDescriptionWithoutError(offer); |
| 1737 | SetRemoteDescriptionAnswerExpectError( |
| 1738 | kSdpWithoutDtlsFingerprint, answer); |
| 1739 | } |
| 1740 | |
| 1741 | // Test that we create a local offer without SDES or DTLS and accept a remote |
| 1742 | // answer without SDES or DTLS when encryption is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1743 | TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1744 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1745 | options_.disable_encryption = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1746 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1747 | |
| 1748 | // Verify that we get a crypto fingerprint in the answer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1749 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1750 | ASSERT_TRUE(offer != NULL); |
| 1751 | VerifyFingerprintStatus(offer->description(), false); |
| 1752 | // Check that we don't have an a=crypto line in the offer. |
| 1753 | VerifyNoCryptoParams(offer->description(), false); |
| 1754 | |
| 1755 | // Now set the local description, which should work, even without a=crypto. |
| 1756 | SetLocalDescriptionWithoutError(offer); |
| 1757 | |
| 1758 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1759 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1760 | JsepSessionDescription* answer = |
| 1761 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1762 | ASSERT_TRUE(answer != NULL); |
| 1763 | VerifyFingerprintStatus(answer->description(), false); |
| 1764 | VerifyNoCryptoParams(answer->description(), false); |
| 1765 | |
| 1766 | // SetRemoteDescription will take the ownership of the answer. |
| 1767 | SetRemoteDescriptionWithoutError(answer); |
| 1768 | } |
| 1769 | |
| 1770 | // Test that we create a local answer without SDES or DTLS and accept a remote |
| 1771 | // offer without SDES or DTLS when encryption is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1772 | TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1773 | options_.disable_encryption = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1774 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1775 | |
| 1776 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1777 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1778 | JsepSessionDescription* offer = |
| 1779 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1780 | ASSERT_TRUE(offer != NULL); |
| 1781 | VerifyFingerprintStatus(offer->description(), false); |
| 1782 | VerifyNoCryptoParams(offer->description(), false); |
| 1783 | |
| 1784 | // SetRemoteDescription will take the ownership of the offer. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1785 | SetRemoteDescriptionWithoutError(offer); |
| 1786 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1787 | // Verify that we get a crypto fingerprint in the answer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1788 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1789 | ASSERT_TRUE(answer != NULL); |
| 1790 | VerifyFingerprintStatus(answer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1791 | // Check that we don't have an a=crypto line in the answer. |
| 1792 | VerifyNoCryptoParams(answer->description(), false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1793 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1794 | // Now set the local description, which should work, even without a=crypto. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1795 | SetLocalDescriptionWithoutError(answer); |
| 1796 | } |
| 1797 | |
| 1798 | TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1799 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1800 | mediastream_signaling_.SendNothing(); |
| 1801 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1802 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1803 | SetLocalDescriptionWithoutError(offer); |
| 1804 | |
| 1805 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1806 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1807 | SetLocalDescriptionWithoutError(offer2); |
| 1808 | } |
| 1809 | |
| 1810 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1811 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1812 | mediastream_signaling_.SendNothing(); |
| 1813 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1814 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1815 | SetRemoteDescriptionWithoutError(offer); |
| 1816 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1817 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1818 | SetRemoteDescriptionWithoutError(offer2); |
| 1819 | } |
| 1820 | |
| 1821 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1822 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1823 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1824 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1825 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1826 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1827 | SetRemoteDescriptionOfferExpectError( |
| 1828 | "Called in wrong state: STATE_SENTINITIATE", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1832 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1833 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1834 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1835 | SetRemoteDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1836 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1837 | SetLocalDescriptionOfferExpectError( |
| 1838 | "Called in wrong state: STATE_RECEIVEDINITIATE", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1842 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1843 | mediastream_signaling_.SendNothing(); |
| 1844 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 1845 | SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE); |
| 1846 | |
| 1847 | JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1848 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1849 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1850 | SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT); |
| 1851 | |
| 1852 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1853 | JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1854 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1855 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1856 | |
| 1857 | SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT); |
| 1858 | |
| 1859 | mediastream_signaling_.SendAudioVideoStream2(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1860 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1861 | SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT); |
| 1862 | } |
| 1863 | |
| 1864 | TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1865 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1866 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1867 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1868 | SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE); |
| 1869 | |
| 1870 | JsepSessionDescription* pranswer = |
| 1871 | CreateRemoteAnswer(session_->local_description()); |
| 1872 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1873 | |
| 1874 | SetRemoteDescriptionExpectState(pranswer, |
| 1875 | BaseSession::STATE_RECEIVEDPRACCEPT); |
| 1876 | |
| 1877 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1878 | JsepSessionDescription* pranswer2 = |
| 1879 | CreateRemoteAnswer(session_->local_description()); |
| 1880 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1881 | |
| 1882 | SetRemoteDescriptionExpectState(pranswer2, |
| 1883 | BaseSession::STATE_RECEIVEDPRACCEPT); |
| 1884 | |
| 1885 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1886 | SessionDescriptionInterface* answer = |
| 1887 | CreateRemoteAnswer(session_->local_description()); |
| 1888 | SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT); |
| 1889 | } |
| 1890 | |
| 1891 | TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1892 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1893 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1894 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 1895 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1896 | SessionDescriptionInterface* answer = |
| 1897 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1898 | SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT", |
| 1899 | answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1903 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1904 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1905 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 1906 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1907 | SessionDescriptionInterface* answer = |
| 1908 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1909 | SetRemoteDescriptionAnswerExpectError( |
| 1910 | "Called in wrong state: STATE_INIT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1914 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1915 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1916 | |
| 1917 | cricket::Candidate candidate; |
| 1918 | candidate.set_component(1); |
| 1919 | JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); |
| 1920 | |
| 1921 | // Fail since we have not set a offer description. |
| 1922 | EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1923 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1924 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1925 | SetLocalDescriptionWithoutError(offer); |
| 1926 | // Candidate should be allowed to add before remote description. |
| 1927 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1928 | candidate.set_component(2); |
| 1929 | JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); |
| 1930 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 1931 | |
| 1932 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 1933 | session_->local_description()); |
| 1934 | SetRemoteDescriptionWithoutError(answer); |
| 1935 | |
| 1936 | // Verifying the candidates are copied properly from internal vector. |
| 1937 | const SessionDescriptionInterface* remote_desc = |
| 1938 | session_->remote_description(); |
| 1939 | ASSERT_TRUE(remote_desc != NULL); |
| 1940 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1941 | const IceCandidateCollection* candidates = |
| 1942 | remote_desc->candidates(kMediaContentIndex0); |
| 1943 | ASSERT_EQ(2u, candidates->count()); |
| 1944 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1945 | EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); |
| 1946 | EXPECT_EQ(1, candidates->at(0)->candidate().component()); |
| 1947 | EXPECT_EQ(2, candidates->at(1)->candidate().component()); |
| 1948 | |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 1949 | // |ice_candidate3| is identical to |ice_candidate2|. It can be added |
| 1950 | // successfully, but the total count of candidates will not increase. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1951 | candidate.set_component(2); |
| 1952 | JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); |
| 1953 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 1954 | ASSERT_EQ(2u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1955 | |
| 1956 | JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); |
| 1957 | EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); |
| 1958 | } |
| 1959 | |
| 1960 | // Test that a remote candidate is added to the remote session description and |
| 1961 | // that it is retained if the remote session description is changed. |
| 1962 | TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1963 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1964 | cricket::Candidate candidate1; |
| 1965 | candidate1.set_component(1); |
| 1966 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 1967 | candidate1); |
| 1968 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1969 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1970 | |
| 1971 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1972 | const SessionDescriptionInterface* remote_desc = |
| 1973 | session_->remote_description(); |
| 1974 | ASSERT_TRUE(remote_desc != NULL); |
| 1975 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1976 | const IceCandidateCollection* candidates = |
| 1977 | remote_desc->candidates(kMediaContentIndex0); |
| 1978 | ASSERT_EQ(1u, candidates->count()); |
| 1979 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1980 | |
| 1981 | // Update the RemoteSessionDescription with a new session description and |
| 1982 | // a candidate and check that the new remote session description contains both |
| 1983 | // candidates. |
| 1984 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 1985 | cricket::Candidate candidate2; |
| 1986 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 1987 | candidate2); |
| 1988 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 1989 | SetRemoteDescriptionWithoutError(offer); |
| 1990 | |
| 1991 | remote_desc = session_->remote_description(); |
| 1992 | ASSERT_TRUE(remote_desc != NULL); |
| 1993 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1994 | candidates = remote_desc->candidates(kMediaContentIndex0); |
| 1995 | ASSERT_EQ(2u, candidates->count()); |
| 1996 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1997 | // Username and password have be updated with the TransportInfo of the |
| 1998 | // SessionDescription, won't be equal to the original one. |
| 1999 | candidate2.set_username(candidates->at(0)->candidate().username()); |
| 2000 | candidate2.set_password(candidates->at(0)->candidate().password()); |
| 2001 | EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate())); |
| 2002 | EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index()); |
| 2003 | // No need to verify the username and password. |
| 2004 | candidate1.set_username(candidates->at(1)->candidate().username()); |
| 2005 | candidate1.set_password(candidates->at(1)->candidate().password()); |
| 2006 | EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); |
| 2007 | |
| 2008 | // Test that the candidate is ignored if we can add the same candidate again. |
| 2009 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2010 | } |
| 2011 | |
| 2012 | // Test that local candidates are added to the local session description and |
| 2013 | // that they are retained if the local session description is changed. |
| 2014 | TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2015 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2016 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2017 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2018 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2019 | |
| 2020 | const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 2021 | const IceCandidateCollection* candidates = |
| 2022 | local_desc->candidates(kMediaContentIndex0); |
| 2023 | ASSERT_TRUE(candidates != NULL); |
| 2024 | EXPECT_EQ(0u, candidates->count()); |
| 2025 | |
| 2026 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 2027 | |
| 2028 | local_desc = session_->local_description(); |
| 2029 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2030 | ASSERT_TRUE(candidates != NULL); |
| 2031 | EXPECT_LT(0u, candidates->count()); |
| 2032 | candidates = local_desc->candidates(1); |
| 2033 | ASSERT_TRUE(candidates != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2034 | EXPECT_EQ(0u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2035 | |
| 2036 | // Update the session descriptions. |
| 2037 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2038 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2039 | |
| 2040 | local_desc = session_->local_description(); |
| 2041 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2042 | ASSERT_TRUE(candidates != NULL); |
| 2043 | EXPECT_LT(0u, candidates->count()); |
| 2044 | candidates = local_desc->candidates(1); |
| 2045 | ASSERT_TRUE(candidates != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2046 | EXPECT_EQ(0u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | // Test that we can set a remote session description with remote candidates. |
| 2050 | TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2051 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2052 | |
| 2053 | cricket::Candidate candidate1; |
| 2054 | candidate1.set_component(1); |
| 2055 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2056 | candidate1); |
| 2057 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2058 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2059 | |
| 2060 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2061 | SetRemoteDescriptionWithoutError(offer); |
| 2062 | |
| 2063 | const SessionDescriptionInterface* remote_desc = |
| 2064 | session_->remote_description(); |
| 2065 | ASSERT_TRUE(remote_desc != NULL); |
| 2066 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2067 | const IceCandidateCollection* candidates = |
| 2068 | remote_desc->candidates(kMediaContentIndex0); |
| 2069 | ASSERT_EQ(1u, candidates->count()); |
| 2070 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2071 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2072 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2073 | SetLocalDescriptionWithoutError(answer); |
| 2074 | } |
| 2075 | |
| 2076 | // Test that offers and answers contains ice candidates when Ice candidates have |
| 2077 | // been gathered. |
| 2078 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2079 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2080 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2081 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2082 | // Ice is started but candidates are not provided until SetLocalDescription |
| 2083 | // is called. |
| 2084 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 2085 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 2086 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2087 | // Wait until at least one local candidate has been collected. |
| 2088 | EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(), |
| 2089 | kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2090 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2091 | rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer()); |
| 2092 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2093 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL); |
| 2094 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2095 | |
| 2096 | SessionDescriptionInterface* remote_offer(CreateRemoteOffer()); |
| 2097 | SetRemoteDescriptionWithoutError(remote_offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2098 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL); |
| 2100 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2101 | SetLocalDescriptionWithoutError(answer); |
| 2102 | } |
| 2103 | |
| 2104 | // Verifies TransportProxy and media channels are created with content names |
| 2105 | // present in the SessionDescription. |
| 2106 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2107 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2108 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2109 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2110 | |
| 2111 | // CreateOffer creates session description with the content names "audio" and |
| 2112 | // "video". Goal is to modify these content names and verify transport channel |
| 2113 | // proxy in the BaseSession, as proxies are created with the content names |
| 2114 | // present in SDP. |
| 2115 | std::string sdp; |
| 2116 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 2117 | const std::string kAudioMid = "a=mid:audio"; |
| 2118 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 2119 | const std::string kVideoMid = "a=mid:video"; |
| 2120 | const std::string kVideoMidReplaceStr = "a=mid:video_content_name"; |
| 2121 | |
| 2122 | // Replacing |audio| with |audio_content_name|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2123 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2124 | kAudioMidReplaceStr.c_str(), |
| 2125 | kAudioMidReplaceStr.length(), |
| 2126 | &sdp); |
| 2127 | // Replacing |video| with |video_content_name|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2128 | rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2129 | kVideoMidReplaceStr.c_str(), |
| 2130 | kVideoMidReplaceStr.length(), |
| 2131 | &sdp); |
| 2132 | |
| 2133 | SessionDescriptionInterface* modified_offer = |
| 2134 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2135 | |
| 2136 | SetRemoteDescriptionWithoutError(modified_offer); |
| 2137 | |
| 2138 | SessionDescriptionInterface* answer = |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2139 | CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2140 | SetLocalDescriptionWithoutError(answer); |
| 2141 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2142 | cricket::TransportChannel* voice_transport_channel = |
| 2143 | session_->voice_rtp_transport_channel(); |
| 2144 | EXPECT_TRUE(voice_transport_channel != NULL); |
| 2145 | EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name"); |
| 2146 | cricket::TransportChannel* video_transport_channel = |
| 2147 | session_->video_rtp_transport_channel(); |
| 2148 | EXPECT_TRUE(video_transport_channel != NULL); |
| 2149 | EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2150 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 2151 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 2152 | } |
| 2153 | |
| 2154 | // Test that an offer contains the correct media content descriptions based on |
| 2155 | // the send streams when no constraints have been set. |
| 2156 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2157 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2158 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2159 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2160 | ASSERT_TRUE(offer != NULL); |
| 2161 | const cricket::ContentInfo* content = |
| 2162 | cricket::GetFirstAudioContent(offer->description()); |
| 2163 | EXPECT_TRUE(content != NULL); |
| 2164 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2165 | EXPECT_TRUE(content == NULL); |
| 2166 | } |
| 2167 | |
| 2168 | // Test that an offer contains the correct media content descriptions based on |
| 2169 | // the send streams when no constraints have been set. |
| 2170 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2171 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2172 | // Test Audio only offer. |
| 2173 | mediastream_signaling_.UseOptionsAudioOnly(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2174 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2175 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2176 | const cricket::ContentInfo* content = |
| 2177 | cricket::GetFirstAudioContent(offer->description()); |
| 2178 | EXPECT_TRUE(content != NULL); |
| 2179 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2180 | EXPECT_TRUE(content == NULL); |
| 2181 | |
| 2182 | // Test Audio / Video offer. |
| 2183 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2184 | offer.reset(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2185 | content = cricket::GetFirstAudioContent(offer->description()); |
| 2186 | EXPECT_TRUE(content != NULL); |
| 2187 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2188 | EXPECT_TRUE(content != NULL); |
| 2189 | } |
| 2190 | |
| 2191 | // Test that an offer contains no media content descriptions if |
| 2192 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 2193 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2194 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2195 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2196 | options.offer_to_receive_audio = 0; |
| 2197 | options.offer_to_receive_video = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2198 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2199 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2200 | CreateOffer(options)); |
| 2201 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2202 | ASSERT_TRUE(offer != NULL); |
| 2203 | const cricket::ContentInfo* content = |
| 2204 | cricket::GetFirstAudioContent(offer->description()); |
| 2205 | EXPECT_TRUE(content == NULL); |
| 2206 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2207 | EXPECT_TRUE(content == NULL); |
| 2208 | } |
| 2209 | |
| 2210 | // Test that an offer contains only audio media content descriptions if |
| 2211 | // kOfferToReceiveAudio constraints are set to true. |
| 2212 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2213 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2214 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2215 | options.offer_to_receive_audio = |
| 2216 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2217 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2218 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2219 | CreateOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2220 | |
| 2221 | const cricket::ContentInfo* content = |
| 2222 | cricket::GetFirstAudioContent(offer->description()); |
| 2223 | EXPECT_TRUE(content != NULL); |
| 2224 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2225 | EXPECT_TRUE(content == NULL); |
| 2226 | } |
| 2227 | |
| 2228 | // Test that an offer contains audio and video media content descriptions if |
| 2229 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 2230 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2231 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2232 | // Test Audio / Video offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2233 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2234 | options.offer_to_receive_audio = |
| 2235 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2236 | options.offer_to_receive_video = |
| 2237 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2238 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2239 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2240 | CreateOffer(options)); |
| 2241 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2242 | const cricket::ContentInfo* content = |
| 2243 | cricket::GetFirstAudioContent(offer->description()); |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2244 | EXPECT_TRUE(content != NULL); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2245 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2246 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2247 | EXPECT_TRUE(content != NULL); |
| 2248 | |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2249 | // Sets constraints to false and verifies that audio/video contents are |
| 2250 | // removed. |
| 2251 | options.offer_to_receive_audio = 0; |
| 2252 | options.offer_to_receive_video = 0; |
| 2253 | offer.reset(CreateOffer(options)); |
| 2254 | |
| 2255 | content = cricket::GetFirstAudioContent(offer->description()); |
| 2256 | EXPECT_TRUE(content == NULL); |
| 2257 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2258 | EXPECT_TRUE(content == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | // Test that an answer can not be created if the last remote description is not |
| 2262 | // an offer. |
| 2263 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2264 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2265 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2266 | SetLocalDescriptionWithoutError(offer); |
| 2267 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2268 | SetRemoteDescriptionWithoutError(answer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2269 | EXPECT_TRUE(CreateAnswer(NULL) == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | // Test that an answer contains the correct media content descriptions when no |
| 2273 | // constraints have been set. |
| 2274 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2275 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2276 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2277 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2278 | SetRemoteDescriptionWithoutError(offer.release()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2279 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2280 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2281 | const cricket::ContentInfo* content = |
| 2282 | cricket::GetFirstAudioContent(answer->description()); |
| 2283 | ASSERT_TRUE(content != NULL); |
| 2284 | EXPECT_FALSE(content->rejected); |
| 2285 | |
| 2286 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2287 | ASSERT_TRUE(content != NULL); |
| 2288 | EXPECT_FALSE(content->rejected); |
| 2289 | } |
| 2290 | |
| 2291 | // Test that an answer contains the correct media content descriptions when no |
| 2292 | // constraints have been set and the offer only contain audio. |
| 2293 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2294 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2295 | // Create a remote offer with audio only. |
| 2296 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2297 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2298 | rtc::scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2299 | CreateRemoteOffer(options)); |
| 2300 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 2301 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 2302 | |
| 2303 | SetRemoteDescriptionWithoutError(offer.release()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2304 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2305 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2306 | const cricket::ContentInfo* content = |
| 2307 | cricket::GetFirstAudioContent(answer->description()); |
| 2308 | ASSERT_TRUE(content != NULL); |
| 2309 | EXPECT_FALSE(content->rejected); |
| 2310 | |
| 2311 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 2312 | } |
| 2313 | |
| 2314 | // Test that an answer contains the correct media content descriptions when no |
| 2315 | // constraints have been set. |
| 2316 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2317 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2318 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2319 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2320 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2321 | // Test with a stream with tracks. |
| 2322 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2323 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2324 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2325 | const cricket::ContentInfo* content = |
| 2326 | cricket::GetFirstAudioContent(answer->description()); |
| 2327 | ASSERT_TRUE(content != NULL); |
| 2328 | EXPECT_FALSE(content->rejected); |
| 2329 | |
| 2330 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2331 | ASSERT_TRUE(content != NULL); |
| 2332 | EXPECT_FALSE(content->rejected); |
| 2333 | } |
| 2334 | |
| 2335 | // Test that an answer contains the correct media content descriptions when |
| 2336 | // constraints have been set but no stream is sent. |
| 2337 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2338 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2339 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2340 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2341 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2342 | |
| 2343 | webrtc::FakeConstraints constraints_no_receive; |
| 2344 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 2345 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 2346 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2347 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2348 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2349 | const cricket::ContentInfo* content = |
| 2350 | cricket::GetFirstAudioContent(answer->description()); |
| 2351 | ASSERT_TRUE(content != NULL); |
| 2352 | EXPECT_TRUE(content->rejected); |
| 2353 | |
| 2354 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2355 | ASSERT_TRUE(content != NULL); |
| 2356 | EXPECT_TRUE(content->rejected); |
| 2357 | } |
| 2358 | |
| 2359 | // Test that an answer contains the correct media content descriptions when |
| 2360 | // constraints have been set and streams are sent. |
| 2361 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2362 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2363 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2364 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2365 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2366 | |
| 2367 | webrtc::FakeConstraints constraints_no_receive; |
| 2368 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 2369 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 2370 | |
| 2371 | // Test with a stream with tracks. |
| 2372 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2373 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2374 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2375 | |
| 2376 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2377 | const cricket::ContentInfo* content = |
| 2378 | cricket::GetFirstAudioContent(answer->description()); |
| 2379 | ASSERT_TRUE(content != NULL); |
| 2380 | EXPECT_FALSE(content->rejected); |
| 2381 | |
| 2382 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2383 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2384 | ASSERT_TRUE(content != NULL); |
| 2385 | EXPECT_FALSE(content->rejected); |
| 2386 | } |
| 2387 | |
| 2388 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 2389 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2390 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2391 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2392 | options.offer_to_receive_audio = |
| 2393 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2394 | options.voice_activity_detection = false; |
| 2395 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2396 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2397 | CreateOffer(options)); |
| 2398 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2399 | const cricket::ContentInfo* content = |
| 2400 | cricket::GetFirstAudioContent(offer->description()); |
| 2401 | EXPECT_TRUE(content != NULL); |
| 2402 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2403 | } |
| 2404 | |
| 2405 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 2406 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2407 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2408 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2409 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2410 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2411 | |
| 2412 | webrtc::FakeConstraints constraints; |
| 2413 | constraints.SetOptionalVAD(false); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2414 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2415 | CreateAnswer(&constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2416 | const cricket::ContentInfo* content = |
| 2417 | cricket::GetFirstAudioContent(answer->description()); |
| 2418 | ASSERT_TRUE(content != NULL); |
| 2419 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2420 | } |
| 2421 | |
| 2422 | // This test verifies the call setup when remote answer with audio only and |
| 2423 | // later updates with video. |
| 2424 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2425 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2426 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2427 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2428 | |
| 2429 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2430 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2431 | |
| 2432 | cricket::MediaSessionOptions options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2433 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 2434 | |
| 2435 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2436 | // and answer; |
| 2437 | SetLocalDescriptionWithoutError(offer); |
| 2438 | SetRemoteDescriptionWithoutError(answer); |
| 2439 | |
| 2440 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2441 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2442 | |
| 2443 | ASSERT_TRUE(video_channel_ == NULL); |
| 2444 | |
| 2445 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 2446 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2447 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 2448 | |
| 2449 | // Let the remote end update the session descriptions, with Audio and Video. |
| 2450 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2451 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2452 | |
| 2453 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2454 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2455 | |
| 2456 | ASSERT_TRUE(video_channel_ != NULL); |
| 2457 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2458 | |
| 2459 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2460 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2461 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2462 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2463 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2464 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2465 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2466 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2467 | |
| 2468 | // Change session back to audio only. |
| 2469 | mediastream_signaling_.UseOptionsAudioOnly(); |
| 2470 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2471 | |
| 2472 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2473 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2474 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2475 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2476 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2477 | } |
| 2478 | |
| 2479 | // This test verifies the call setup when remote answer with video only and |
| 2480 | // later updates with audio. |
| 2481 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2482 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2483 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2484 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2485 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2486 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2487 | |
| 2488 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 2489 | options.recv_audio = false; |
| 2490 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2491 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2492 | offer, options, cricket::SEC_ENABLED); |
| 2493 | |
| 2494 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2495 | // and answer. |
| 2496 | SetLocalDescriptionWithoutError(offer); |
| 2497 | SetRemoteDescriptionWithoutError(answer); |
| 2498 | |
| 2499 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2500 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2501 | |
| 2502 | ASSERT_TRUE(voice_channel_ == NULL); |
| 2503 | ASSERT_TRUE(video_channel_ != NULL); |
| 2504 | |
| 2505 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2506 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2507 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 2508 | |
| 2509 | // Update the session descriptions, with Audio and Video. |
| 2510 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2511 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2512 | |
| 2513 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2514 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2515 | |
| 2516 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2517 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2518 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2519 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2520 | |
| 2521 | // Change session back to video only. |
| 2522 | mediastream_signaling_.UseOptionsVideoOnly(); |
| 2523 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2524 | |
| 2525 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2526 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2527 | |
| 2528 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2529 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2530 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2531 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2532 | } |
| 2533 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2534 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2535 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2536 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2537 | scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2538 | VerifyCryptoParams(offer->description()); |
| 2539 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2540 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2541 | VerifyCryptoParams(answer->description()); |
| 2542 | } |
| 2543 | |
| 2544 | TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2545 | options_.disable_encryption = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2546 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2547 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2548 | scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2549 | VerifyNoCryptoParams(offer->description(), false); |
| 2550 | } |
| 2551 | |
| 2552 | TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2553 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2554 | VerifyAnswerFromNonCryptoOffer(); |
| 2555 | } |
| 2556 | |
| 2557 | TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2558 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2559 | VerifyAnswerFromCryptoOffer(); |
| 2560 | } |
| 2561 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2562 | // This test verifies that setLocalDescription fails if |
| 2563 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2564 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2565 | Init(); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2566 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2567 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2568 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2569 | std::string sdp; |
| 2570 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2571 | SessionDescriptionInterface* modified_offer = |
| 2572 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2573 | SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | // This test verifies that setRemoteDescription fails if |
| 2577 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2578 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2579 | Init(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2580 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2581 | std::string sdp; |
| 2582 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2583 | SessionDescriptionInterface* modified_offer = |
| 2584 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2585 | SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2588 | // This test verifies that setLocalDescription fails if local offer has |
| 2589 | // too short ice ufrag and pwd strings. |
| 2590 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2591 | Init(); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2592 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2593 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2594 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2595 | std::string sdp; |
| 2596 | // Modifying ice ufrag and pwd in local offer with strings smaller than the |
| 2597 | // recommended values of 4 and 22 bytes respectively. |
| 2598 | ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp); |
| 2599 | SessionDescriptionInterface* modified_offer = |
| 2600 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2601 | std::string error; |
| 2602 | EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error)); |
| 2603 | |
| 2604 | // Test with string greater than 256. |
| 2605 | sdp.clear(); |
| 2606 | ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd, |
| 2607 | &sdp); |
| 2608 | modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp, |
| 2609 | NULL); |
| 2610 | EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error)); |
| 2611 | } |
| 2612 | |
| 2613 | // This test verifies that setRemoteDescription fails if remote offer has |
| 2614 | // too short ice ufrag and pwd strings. |
| 2615 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2616 | Init(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2617 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2618 | std::string sdp; |
| 2619 | // Modifying ice ufrag and pwd in remote offer with strings smaller than the |
| 2620 | // recommended values of 4 and 22 bytes respectively. |
| 2621 | ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp); |
| 2622 | SessionDescriptionInterface* modified_offer = |
| 2623 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2624 | std::string error; |
| 2625 | EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error)); |
| 2626 | |
| 2627 | sdp.clear(); |
| 2628 | ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd, |
| 2629 | &sdp); |
| 2630 | modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp, |
| 2631 | NULL); |
| 2632 | EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error)); |
| 2633 | } |
| 2634 | |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2635 | // Test that if the remote description indicates the peer requested ICE restart |
| 2636 | // (via a new ufrag or pwd), the old ICE candidates are not copied, |
| 2637 | // and vice versa. |
| 2638 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) { |
| 2639 | Init(); |
| 2640 | scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 2641 | |
| 2642 | // Create the first offer. |
| 2643 | std::string sdp; |
| 2644 | ModifyIceUfragPwdLines(offer.get(), "0123456789012345", |
| 2645 | "abcdefghijklmnopqrstuvwx", &sdp); |
| 2646 | SessionDescriptionInterface* offer1 = |
| 2647 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2648 | cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), |
| 2649 | 0, "", "", "relay", 0, ""); |
| 2650 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2651 | candidate1); |
| 2652 | EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1)); |
| 2653 | SetRemoteDescriptionWithoutError(offer1); |
| 2654 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2655 | |
| 2656 | // The second offer has the same ufrag and pwd but different address. |
| 2657 | sdp.clear(); |
| 2658 | ModifyIceUfragPwdLines(offer.get(), "0123456789012345", |
| 2659 | "abcdefghijklmnopqrstuvwx", &sdp); |
| 2660 | SessionDescriptionInterface* offer2 = |
| 2661 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2662 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2663 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2664 | candidate1); |
| 2665 | EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2)); |
| 2666 | SetRemoteDescriptionWithoutError(offer2); |
| 2667 | EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); |
| 2668 | |
| 2669 | // The third offer has a different ufrag and different address. |
| 2670 | sdp.clear(); |
| 2671 | ModifyIceUfragPwdLines(offer.get(), "0123456789012333", |
| 2672 | "abcdefghijklmnopqrstuvwx", &sdp); |
| 2673 | SessionDescriptionInterface* offer3 = |
| 2674 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2675 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); |
| 2676 | JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, |
| 2677 | candidate1); |
| 2678 | EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3)); |
| 2679 | SetRemoteDescriptionWithoutError(offer3); |
| 2680 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2681 | |
| 2682 | // The fourth offer has no candidate but a different ufrag/pwd. |
| 2683 | sdp.clear(); |
| 2684 | ModifyIceUfragPwdLines(offer.get(), "0123456789012444", |
| 2685 | "abcdefghijklmnopqrstuvyz", &sdp); |
| 2686 | SessionDescriptionInterface* offer4 = |
| 2687 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2688 | SetRemoteDescriptionWithoutError(offer4); |
| 2689 | EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); |
| 2690 | } |
| 2691 | |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2692 | // Test that candidates sent to the "video" transport do not get pushed down to |
| 2693 | // the "audio" transport channel when bundling using TransportProxy. |
| 2694 | TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { |
| 2695 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2696 | |
| 2697 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
| 2698 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2699 | |
| 2700 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2701 | options.use_rtp_mux = true; |
| 2702 | |
| 2703 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2704 | SetRemoteDescriptionWithoutError(offer); |
| 2705 | |
| 2706 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
| 2707 | SetLocalDescriptionWithoutError(answer); |
| 2708 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2709 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2710 | session_->video_rtp_transport_channel()); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2711 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2712 | cricket::BaseChannel* voice_channel = session_->voice_channel(); |
| 2713 | ASSERT(voice_channel != NULL); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2714 | |
| 2715 | // Checks if one of the transport channels contains a connection using a given |
| 2716 | // port. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2717 | auto connection_with_remote_port = [this, voice_channel](int port) { |
| 2718 | cricket::SessionStats stats; |
| 2719 | session_->GetChannelTransportStats(voice_channel, &stats); |
| 2720 | for (auto& kv : stats.transport_stats) { |
| 2721 | for (auto& chan_stat : kv.second.channel_stats) { |
| 2722 | for (auto& conn_info : chan_stat.connection_infos) { |
| 2723 | if (conn_info.remote_candidate.address().port() == port) { |
| 2724 | return true; |
| 2725 | } |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | } |
| 2729 | return false; |
| 2730 | }; |
| 2731 | |
| 2732 | EXPECT_FALSE(connection_with_remote_port(5000)); |
| 2733 | EXPECT_FALSE(connection_with_remote_port(5001)); |
| 2734 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2735 | |
| 2736 | // The way the *_WAIT checks work is they only wait if the condition fails, |
| 2737 | // which does not help in the case where state is not changing. This is |
| 2738 | // problematic in this test since we want to verify that adding a video |
| 2739 | // candidate does _not_ change state. So we interleave candidates and assume |
| 2740 | // that messages are executed in the order they were posted. |
| 2741 | |
| 2742 | // First audio candidate. |
| 2743 | cricket::Candidate candidate0; |
| 2744 | candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
| 2745 | candidate0.set_component(1); |
| 2746 | candidate0.set_protocol("udp"); |
| 2747 | JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0, |
| 2748 | candidate0); |
| 2749 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0)); |
| 2750 | |
| 2751 | // Video candidate. |
| 2752 | cricket::Candidate candidate1; |
| 2753 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2754 | candidate1.set_component(1); |
| 2755 | candidate1.set_protocol("udp"); |
| 2756 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2757 | candidate1); |
| 2758 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2759 | |
| 2760 | // Second audio candidate. |
| 2761 | cricket::Candidate candidate2; |
| 2762 | candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001)); |
| 2763 | candidate2.set_component(1); |
| 2764 | candidate2.set_protocol("udp"); |
| 2765 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2766 | candidate2); |
| 2767 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2768 | |
| 2769 | EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000); |
| 2770 | EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000); |
| 2771 | |
| 2772 | // No need here for a _WAIT check since we are checking that state hasn't |
| 2773 | // changed: if this is false we would be doing waits for nothing and if this |
| 2774 | // is true then there will be no messages processed anyways. |
| 2775 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2776 | } |
| 2777 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2778 | // kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2779 | TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) { |
| 2780 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2781 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2782 | |
| 2783 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2784 | options.use_rtp_mux = true; |
| 2785 | |
| 2786 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2787 | SetLocalDescriptionWithoutError(offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2788 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2789 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2790 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2791 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2792 | mediastream_signaling_.SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2793 | SessionDescriptionInterface* answer = |
| 2794 | CreateRemoteAnswer(session_->local_description()); |
| 2795 | SetRemoteDescriptionWithoutError(answer); |
| 2796 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2797 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2798 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2801 | // kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2802 | TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) { |
| 2803 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
| 2804 | mediastream_signaling_.SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2805 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2806 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2807 | options.use_rtp_mux = true; |
| 2808 | |
| 2809 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2810 | SetLocalDescriptionWithoutError(offer); |
| 2811 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2812 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2813 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2814 | |
| 2815 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2816 | |
| 2817 | // Remove BUNDLE from the answer. |
| 2818 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
| 2819 | CreateRemoteAnswer(session_->local_description())); |
| 2820 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2821 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2822 | JsepSessionDescription* modified_answer = |
| 2823 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2824 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2825 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 2826 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2827 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2828 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer. |
| 2832 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) { |
| 2833 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 2834 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2835 | |
| 2836 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2837 | options.use_rtp_mux = true; |
| 2838 | |
| 2839 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2840 | SetLocalDescriptionWithoutError(offer); |
| 2841 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2842 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2843 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2844 | |
| 2845 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2846 | SessionDescriptionInterface* answer = |
| 2847 | CreateRemoteAnswer(session_->local_description()); |
| 2848 | SetRemoteDescriptionWithoutError(answer); |
| 2849 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2850 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2851 | session_->video_rtp_transport_channel()); |
| 2852 | } |
| 2853 | |
| 2854 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no |
| 2855 | // audio content in the answer. |
| 2856 | TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) { |
| 2857 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 2858 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2859 | |
| 2860 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2861 | options.use_rtp_mux = true; |
| 2862 | |
| 2863 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2864 | SetLocalDescriptionWithoutError(offer); |
| 2865 | |
| 2866 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2867 | session_->video_rtp_transport_channel()); |
| 2868 | |
| 2869 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2870 | cricket::MediaSessionOptions recv_options; |
| 2871 | recv_options.recv_audio = false; |
| 2872 | recv_options.recv_video = true; |
| 2873 | SessionDescriptionInterface* answer = |
| 2874 | CreateRemoteAnswer(session_->local_description(), recv_options); |
| 2875 | SetRemoteDescriptionWithoutError(answer); |
| 2876 | |
| 2877 | EXPECT_TRUE(NULL == session_->voice_channel()); |
| 2878 | EXPECT_TRUE(NULL != session_->video_rtp_transport_channel()); |
| 2879 | |
| 2880 | session_->Terminate(); |
| 2881 | EXPECT_TRUE(NULL == session_->voice_rtp_transport_channel()); |
| 2882 | EXPECT_TRUE(NULL == session_->voice_rtcp_transport_channel()); |
| 2883 | EXPECT_TRUE(NULL == session_->video_rtp_transport_channel()); |
| 2884 | EXPECT_TRUE(NULL == session_->video_rtcp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | // kBundlePolicyMaxBundle policy but no BUNDLE in the answer. |
| 2888 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) { |
| 2889 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 2890 | mediastream_signaling_.SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2891 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2892 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2893 | options.use_rtp_mux = true; |
| 2894 | |
| 2895 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2896 | SetLocalDescriptionWithoutError(offer); |
| 2897 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2898 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2899 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2900 | |
| 2901 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2902 | |
| 2903 | // Remove BUNDLE from the answer. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2904 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2905 | CreateRemoteAnswer(session_->local_description())); |
| 2906 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2907 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2908 | JsepSessionDescription* modified_answer = |
| 2909 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2910 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2911 | SetRemoteDescriptionWithoutError(modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2912 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2913 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2914 | session_->video_rtp_transport_channel()); |
| 2915 | } |
| 2916 | |
| 2917 | // kBundlePolicyMaxBundle policy with BUNDLE in the remote offer. |
| 2918 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) { |
| 2919 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 2920 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2921 | |
| 2922 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2923 | SetRemoteDescriptionWithoutError(offer); |
| 2924 | |
| 2925 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2926 | session_->video_rtp_transport_channel()); |
| 2927 | |
| 2928 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2929 | SessionDescriptionInterface* answer = CreateAnswer(nullptr); |
| 2930 | SetLocalDescriptionWithoutError(answer); |
| 2931 | |
| 2932 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2933 | session_->video_rtp_transport_channel()); |
| 2934 | } |
| 2935 | |
| 2936 | // kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer. |
| 2937 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) { |
| 2938 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 2939 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2940 | |
| 2941 | // Remove BUNDLE from the offer. |
| 2942 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 2943 | cricket::SessionDescription* offer_copy = offer->description()->Copy(); |
| 2944 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2945 | JsepSessionDescription* modified_offer = |
| 2946 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2947 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 2948 | |
| 2949 | // Expect an error when applying the remote description |
| 2950 | SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, |
| 2951 | kCreateChannelFailed, modified_offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2952 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2953 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2954 | // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2955 | TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { |
| 2956 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
| 2957 | mediastream_signaling_.SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2958 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2959 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2960 | options.use_rtp_mux = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2961 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2962 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2963 | SetLocalDescriptionWithoutError(offer); |
| 2964 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2965 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2966 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2967 | |
| 2968 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2969 | SessionDescriptionInterface* answer = |
| 2970 | CreateRemoteAnswer(session_->local_description()); |
| 2971 | SetRemoteDescriptionWithoutError(answer); |
| 2972 | |
| 2973 | // This should lead to an audio-only call but isn't implemented |
| 2974 | // correctly yet. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2975 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2976 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2979 | // kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2980 | TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) { |
| 2981 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
| 2982 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2983 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2984 | options.use_rtp_mux = true; |
| 2985 | |
| 2986 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2987 | SetLocalDescriptionWithoutError(offer); |
| 2988 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2989 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2990 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2991 | |
| 2992 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2993 | |
| 2994 | // Remove BUNDLE from the answer. |
| 2995 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
| 2996 | CreateRemoteAnswer(session_->local_description())); |
| 2997 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2998 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2999 | JsepSessionDescription* modified_answer = |
| 3000 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3001 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3002 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 3003 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3004 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3005 | session_->video_rtp_transport_channel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3008 | // kBundlePolicyMaxbundle and then we call SetRemoteDescription first. |
| 3009 | TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) { |
| 3010 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 3011 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3012 | |
| 3013 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3014 | options.use_rtp_mux = true; |
| 3015 | |
| 3016 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3017 | SetRemoteDescriptionWithoutError(offer); |
| 3018 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3019 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3020 | session_->video_rtp_transport_channel()); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3023 | TEST_F(WebRtcSessionTest, TestRequireRtcpMux) { |
| 3024 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
| 3025 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3026 | |
| 3027 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3028 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3029 | SetLocalDescriptionWithoutError(offer); |
| 3030 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3031 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3032 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3033 | |
| 3034 | mediastream_signaling_.SendAudioVideoStream2(); |
| 3035 | SessionDescriptionInterface* answer = |
| 3036 | CreateRemoteAnswer(session_->local_description()); |
| 3037 | SetRemoteDescriptionWithoutError(answer); |
| 3038 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3039 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3040 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) { |
| 3044 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
| 3045 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3046 | |
| 3047 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3048 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3049 | SetLocalDescriptionWithoutError(offer); |
| 3050 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3051 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL); |
| 3052 | EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3053 | |
| 3054 | mediastream_signaling_.SendAudioVideoStream2(); |
| 3055 | SessionDescriptionInterface* answer = |
| 3056 | CreateRemoteAnswer(session_->local_description()); |
| 3057 | SetRemoteDescriptionWithoutError(answer); |
| 3058 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3059 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3060 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3063 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 3064 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 3065 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3066 | Init(); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3067 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3068 | |
| 3069 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3070 | options.use_rtp_mux = true; |
| 3071 | |
| 3072 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3073 | std::string offer_str; |
| 3074 | offer->ToString(&offer_str); |
| 3075 | // Disable rtcp-mux |
| 3076 | const std::string rtcp_mux = "rtcp-mux"; |
| 3077 | const std::string xrtcp_mux = "xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3078 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3079 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 3080 | &offer_str); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3081 | JsepSessionDescription* local_offer = |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3082 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3083 | EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3084 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3085 | JsepSessionDescription* remote_offer = |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3086 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3087 | EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3088 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3089 | // Trying unmodified SDP. |
| 3090 | SetLocalDescriptionWithoutError(offer); |
| 3091 | } |
| 3092 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3093 | TEST_F(WebRtcSessionTest, SetAudioPlayout) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3094 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3095 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3096 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3097 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3098 | ASSERT_TRUE(channel != NULL); |
| 3099 | ASSERT_EQ(1u, channel->recv_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3100 | uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 3101 | double volume; |
| 3102 | EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); |
| 3103 | EXPECT_EQ(1, volume); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3104 | rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3105 | session_->SetAudioPlayout(receive_ssrc, false, renderer.get()); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 3106 | EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); |
| 3107 | EXPECT_EQ(0, volume); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3108 | session_->SetAudioPlayout(receive_ssrc, true, NULL); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 3109 | EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); |
| 3110 | EXPECT_EQ(1, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | TEST_F(WebRtcSessionTest, SetAudioSend) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3114 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3115 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3116 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3117 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3118 | ASSERT_TRUE(channel != NULL); |
| 3119 | ASSERT_EQ(1u, channel->send_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3120 | uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3121 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3122 | |
| 3123 | cricket::AudioOptions options; |
| 3124 | options.echo_cancellation.Set(true); |
| 3125 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3126 | rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3127 | session_->SetAudioSend(send_ssrc, false, options, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3128 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 3129 | EXPECT_FALSE(channel->options().echo_cancellation.IsSet()); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3130 | EXPECT_TRUE(renderer->sink() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3131 | |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3132 | // This will trigger SetSink(NULL) to the |renderer|. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3133 | session_->SetAudioSend(send_ssrc, true, options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3134 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3135 | bool value; |
| 3136 | EXPECT_TRUE(channel->options().echo_cancellation.Get(&value)); |
| 3137 | EXPECT_TRUE(value); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3138 | EXPECT_TRUE(renderer->sink() == NULL); |
| 3139 | } |
| 3140 | |
| 3141 | TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3142 | Init(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3143 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3144 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3145 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3146 | ASSERT_TRUE(channel != NULL); |
| 3147 | ASSERT_EQ(1u, channel->send_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3148 | uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3149 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3150 | rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3151 | cricket::AudioOptions options; |
| 3152 | session_->SetAudioSend(send_ssrc, true, options, renderer.get()); |
| 3153 | EXPECT_TRUE(renderer->sink() != NULL); |
| 3154 | |
| 3155 | // Delete the |renderer| and it will trigger OnClose() to the sink, and this |
| 3156 | // will invalidate the |renderer_| pointer in the sink and prevent getting a |
| 3157 | // SetSink(NULL) callback afterwards. |
| 3158 | renderer.reset(); |
| 3159 | |
| 3160 | // This will trigger SetSink(NULL) if no OnClose() callback. |
| 3161 | session_->SetAudioSend(send_ssrc, true, options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | TEST_F(WebRtcSessionTest, SetVideoPlayout) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3165 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3166 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3167 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3168 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 3169 | ASSERT_TRUE(channel != NULL); |
| 3170 | ASSERT_LT(0u, channel->renderers().size()); |
| 3171 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 3172 | ASSERT_EQ(1u, channel->recv_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3173 | uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3174 | cricket::FakeVideoRenderer renderer; |
| 3175 | session_->SetVideoPlayout(receive_ssrc, true, &renderer); |
| 3176 | EXPECT_TRUE(channel->renderers().begin()->second == &renderer); |
| 3177 | session_->SetVideoPlayout(receive_ssrc, false, &renderer); |
| 3178 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 3179 | } |
| 3180 | |
| 3181 | TEST_F(WebRtcSessionTest, SetVideoSend) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3182 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3183 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3184 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3185 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 3186 | ASSERT_TRUE(channel != NULL); |
| 3187 | ASSERT_EQ(1u, channel->send_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3188 | uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3189 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3190 | cricket::VideoOptions* options = NULL; |
| 3191 | session_->SetVideoSend(send_ssrc, false, options); |
| 3192 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 3193 | session_->SetVideoSend(send_ssrc, true, options); |
| 3194 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3195 | } |
| 3196 | |
| 3197 | TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { |
| 3198 | TestCanInsertDtmf(false); |
| 3199 | } |
| 3200 | |
| 3201 | TEST_F(WebRtcSessionTest, CanInsertDtmf) { |
| 3202 | TestCanInsertDtmf(true); |
| 3203 | } |
| 3204 | |
| 3205 | TEST_F(WebRtcSessionTest, InsertDtmf) { |
| 3206 | // Setup |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3207 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3208 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3209 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3210 | FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3211 | EXPECT_EQ(0U, channel->dtmf_info_queue().size()); |
| 3212 | |
| 3213 | // Insert DTMF |
| 3214 | const int expected_flags = DF_SEND; |
| 3215 | const int expected_duration = 90; |
| 3216 | session_->InsertDtmf(kAudioTrack1, 0, expected_duration); |
| 3217 | session_->InsertDtmf(kAudioTrack1, 1, expected_duration); |
| 3218 | session_->InsertDtmf(kAudioTrack1, 2, expected_duration); |
| 3219 | |
| 3220 | // Verify |
| 3221 | ASSERT_EQ(3U, channel->dtmf_info_queue().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3222 | const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3223 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0, |
| 3224 | expected_duration, expected_flags)); |
| 3225 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1, |
| 3226 | expected_duration, expected_flags)); |
| 3227 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2, |
| 3228 | expected_duration, expected_flags)); |
| 3229 | } |
| 3230 | |
| 3231 | // This test verifies the |initiator| flag when session initiates the call. |
| 3232 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3233 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3234 | EXPECT_FALSE(session_->initiator()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3235 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3236 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3237 | SetLocalDescriptionWithoutError(offer); |
| 3238 | EXPECT_TRUE(session_->initiator()); |
| 3239 | SetRemoteDescriptionWithoutError(answer); |
| 3240 | EXPECT_TRUE(session_->initiator()); |
| 3241 | } |
| 3242 | |
| 3243 | // This test verifies the |initiator| flag when session receives the call. |
| 3244 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3245 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3246 | EXPECT_FALSE(session_->initiator()); |
| 3247 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3248 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3249 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3250 | |
| 3251 | EXPECT_FALSE(session_->initiator()); |
| 3252 | SetLocalDescriptionWithoutError(answer); |
| 3253 | EXPECT_FALSE(session_->initiator()); |
| 3254 | } |
| 3255 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3256 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 3257 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3258 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3259 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3260 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3261 | SetLocalDescriptionWithoutError(offer); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3262 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3263 | CreateRemoteAnswer(session_->local_description())); |
| 3264 | |
| 3265 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3266 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3267 | JsepSessionDescription* modified_answer = |
| 3268 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3269 | |
| 3270 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 3271 | answer->session_id(), |
| 3272 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3273 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3274 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3275 | // Different content names. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3276 | std::string sdp; |
| 3277 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 3278 | const std::string kAudioMid = "a=mid:audio"; |
| 3279 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3280 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3281 | kAudioMidReplaceStr.c_str(), |
| 3282 | kAudioMidReplaceStr.length(), |
| 3283 | &sdp); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3284 | SessionDescriptionInterface* modified_answer1 = |
| 3285 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3286 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3287 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3288 | // Different media types. |
| 3289 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 3290 | const std::string kAudioMline = "m=audio"; |
| 3291 | const std::string kAudioMlineReplaceStr = "m=video"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3292 | rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(), |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3293 | kAudioMlineReplaceStr.c_str(), |
| 3294 | kAudioMlineReplaceStr.length(), |
| 3295 | &sdp); |
| 3296 | SessionDescriptionInterface* modified_answer2 = |
| 3297 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 3298 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2); |
| 3299 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3300 | SetRemoteDescriptionWithoutError(answer.release()); |
| 3301 | } |
| 3302 | |
| 3303 | // Verifying remote offer and local answer have matching m-lines as per |
| 3304 | // RFC 3264. |
| 3305 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3306 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3307 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3308 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3309 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3310 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3311 | |
| 3312 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3313 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3314 | JsepSessionDescription* modified_answer = |
| 3315 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3316 | |
| 3317 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 3318 | answer->session_id(), |
| 3319 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3320 | SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3321 | SetLocalDescriptionWithoutError(answer); |
| 3322 | } |
| 3323 | |
| 3324 | // This test verifies that WebRtcSession does not start candidate allocation |
| 3325 | // before SetLocalDescription is called. |
| 3326 | TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3327 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3328 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3329 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3330 | cricket::Candidate candidate; |
| 3331 | candidate.set_component(1); |
| 3332 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 3333 | candidate); |
| 3334 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 3335 | cricket::Candidate candidate1; |
| 3336 | candidate1.set_component(1); |
| 3337 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 3338 | candidate1); |
| 3339 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 3340 | SetRemoteDescriptionWithoutError(offer); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3341 | ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL); |
| 3342 | ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3343 | |
| 3344 | // Pump for 1 second and verify that no candidates are generated. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3345 | rtc::Thread::Current()->ProcessMessages(1000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3346 | EXPECT_TRUE(observer_.mline_0_candidates_.empty()); |
| 3347 | EXPECT_TRUE(observer_.mline_1_candidates_.empty()); |
| 3348 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3349 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3350 | SetLocalDescriptionWithoutError(answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3351 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 3352 | } |
| 3353 | |
| 3354 | // This test verifies that crypto parameter is updated in local session |
| 3355 | // description as per security policy set in MediaSessionDescriptionFactory. |
| 3356 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3357 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3358 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3359 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3360 | |
| 3361 | // Making sure SetLocalDescription correctly sets crypto value in |
| 3362 | // SessionDescription object after de-serialization of sdp string. The value |
| 3363 | // will be set as per MediaSessionDescriptionFactory. |
| 3364 | std::string offer_str; |
| 3365 | offer->ToString(&offer_str); |
| 3366 | SessionDescriptionInterface* jsep_offer_str = |
| 3367 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 3368 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 3369 | EXPECT_TRUE(session_->voice_channel()->secure_required()); |
| 3370 | EXPECT_TRUE(session_->video_channel()->secure_required()); |
| 3371 | } |
| 3372 | |
| 3373 | // This test verifies the crypto parameter when security is disabled. |
| 3374 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3375 | options_.disable_encryption = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3376 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3377 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3378 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3379 | |
| 3380 | // Making sure SetLocalDescription correctly sets crypto value in |
| 3381 | // SessionDescription object after de-serialization of sdp string. The value |
| 3382 | // will be set as per MediaSessionDescriptionFactory. |
| 3383 | std::string offer_str; |
| 3384 | offer->ToString(&offer_str); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3385 | SessionDescriptionInterface* jsep_offer_str = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3386 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 3387 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 3388 | EXPECT_FALSE(session_->voice_channel()->secure_required()); |
| 3389 | EXPECT_FALSE(session_->video_channel()->secure_required()); |
| 3390 | } |
| 3391 | |
| 3392 | // This test verifies that an answer contains new ufrag and password if an offer |
| 3393 | // with new ufrag and password is received. |
| 3394 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3395 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3396 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3397 | options.recv_video = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3398 | rtc::scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3399 | CreateRemoteOffer(options)); |
| 3400 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3401 | |
| 3402 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3403 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3404 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3405 | SetLocalDescriptionWithoutError(answer.release()); |
| 3406 | |
| 3407 | // Receive an offer with new ufrag and password. |
| 3408 | options.transport_options.ice_restart = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3409 | rtc::scoped_ptr<JsepSessionDescription> updated_offer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3410 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3411 | SetRemoteDescriptionWithoutError(updated_offer1.release()); |
| 3412 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3413 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3414 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3415 | |
| 3416 | CompareIceUfragAndPassword(updated_answer1->description(), |
| 3417 | session_->local_description()->description(), |
| 3418 | false); |
| 3419 | |
| 3420 | SetLocalDescriptionWithoutError(updated_answer1.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3421 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3422 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3423 | // This test verifies that an answer contains old ufrag and password if an offer |
| 3424 | // with old ufrag and password is received. |
| 3425 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3426 | Init(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3427 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3428 | options.recv_video = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3429 | rtc::scoped_ptr<JsepSessionDescription> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3430 | CreateRemoteOffer(options)); |
| 3431 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3432 | |
| 3433 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3434 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3435 | CreateAnswer(NULL)); |
| 3436 | SetLocalDescriptionWithoutError(answer.release()); |
| 3437 | |
| 3438 | // Receive an offer without changed ufrag or password. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3439 | options.transport_options.ice_restart = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3440 | rtc::scoped_ptr<JsepSessionDescription> updated_offer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3441 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3442 | SetRemoteDescriptionWithoutError(updated_offer2.release()); |
| 3443 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3444 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3445 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3446 | |
| 3447 | CompareIceUfragAndPassword(updated_answer2->description(), |
| 3448 | session_->local_description()->description(), |
| 3449 | true); |
| 3450 | |
| 3451 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 3452 | } |
| 3453 | |
| 3454 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3455 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3456 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3457 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3458 | const std::string session_id_orig = offer->session_id(); |
| 3459 | const std::string session_version_orig = offer->session_version(); |
| 3460 | SetLocalDescriptionWithoutError(offer); |
| 3461 | |
| 3462 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3463 | video_channel_->set_fail_set_send_codecs(true); |
| 3464 | |
| 3465 | mediastream_signaling_.SendAudioVideoStream2(); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3466 | SessionDescriptionInterface* answer = |
| 3467 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3468 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 3472 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 3473 | // Lets try with only UDP ports. |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3474 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3475 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3476 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3477 | TestLoopbackCall(); |
| 3478 | } |
| 3479 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3480 | TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3481 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3482 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3483 | cricket::PORTALLOCATOR_ENABLE_IPV6 | |
| 3484 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 3485 | |
| 3486 | // best connection is IPv6 since it has higher network preference. |
| 3487 | LoopbackNetworkConfiguration config; |
| 3488 | config.test_ipv6_network_ = true; |
| 3489 | config.best_connection_after_initial_ice_converged_ = |
| 3490 | LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1); |
| 3491 | |
| 3492 | TestLoopbackCall(config); |
| 3493 | } |
| 3494 | |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 3495 | // Runs the loopback call test with BUNDLE and STUN enabled. |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3496 | TEST_F(WebRtcSessionTest, TestIceStatesBundle) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3497 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 3498 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3499 | TestLoopbackCall(); |
| 3500 | } |
| 3501 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3502 | TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3503 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3504 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3505 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3506 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3507 | cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT; |
| 3508 | std::string error_code_str = "ERROR_CONTENT"; |
| 3509 | std::string error_desc = "Fake session error description."; |
| 3510 | session_->SetError(error_code, error_desc); |
| 3511 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3512 | SessionDescriptionInterface* offer = CreateRemoteOffer(options); |
| 3513 | SessionDescriptionInterface* answer = |
| 3514 | CreateRemoteAnswer(offer, options); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3515 | |
| 3516 | std::string action; |
| 3517 | std::ostringstream session_error_msg; |
| 3518 | session_error_msg << kSessionError << error_code_str << ". "; |
| 3519 | session_error_msg << kSessionErrorDesc << error_desc << "."; |
| 3520 | SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer); |
| 3521 | SetLocalDescriptionExpectError(action, session_error_msg.str(), answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
| 3525 | constraints_.reset(new FakeConstraints()); |
| 3526 | constraints_->AddOptional( |
| 3527 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3528 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3529 | |
| 3530 | SetLocalDescriptionWithDataChannel(); |
| 3531 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 3532 | } |
| 3533 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3534 | TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3535 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3536 | |
| 3537 | constraints_.reset(new FakeConstraints()); |
| 3538 | constraints_->AddOptional( |
| 3539 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3540 | options_.disable_sctp_data_channels = false; |
| 3541 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3542 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3543 | |
| 3544 | SetLocalDescriptionWithDataChannel(); |
| 3545 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 3546 | } |
| 3547 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3548 | TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3549 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 3550 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3551 | InitWithDtls(GetParam()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3552 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3553 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3554 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3555 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 3556 | } |
| 3557 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3558 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3559 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3560 | SetFactoryDtlsSrtp(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3561 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3562 | |
| 3563 | // Create remote offer with SCTP. |
| 3564 | cricket::MediaSessionOptions options; |
| 3565 | options.data_channel_type = cricket::DCT_SCTP; |
| 3566 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3567 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3568 | SetRemoteDescriptionWithoutError(offer); |
| 3569 | |
| 3570 | // Verifies the answer contains SCTP. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3571 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3572 | EXPECT_TRUE(answer != NULL); |
| 3573 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 3574 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3577 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3578 | constraints_.reset(new FakeConstraints()); |
| 3579 | constraints_->AddOptional( |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3580 | webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3581 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3582 | |
| 3583 | SetLocalDescriptionWithDataChannel(); |
| 3584 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 3585 | } |
| 3586 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3587 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3588 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3589 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3590 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3591 | |
| 3592 | SetLocalDescriptionWithDataChannel(); |
| 3593 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 3594 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3595 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3596 | TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3597 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3598 | options_.disable_sctp_data_channels = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3599 | InitWithDtls(GetParam()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3600 | |
| 3601 | SetLocalDescriptionWithDataChannel(); |
| 3602 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 3603 | } |
| 3604 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3605 | TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3606 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3607 | const int new_send_port = 9998; |
| 3608 | const int new_recv_port = 7775; |
| 3609 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3610 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3611 | SetFactoryDtlsSrtp(); |
| 3612 | |
| 3613 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 3614 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 3615 | // let the session description get parsed. That'll get the proper codecs |
| 3616 | // into the stream. |
| 3617 | cricket::MediaSessionOptions options; |
| 3618 | JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort( |
| 3619 | "stream1", new_send_port, options); |
| 3620 | |
| 3621 | // SetRemoteDescription will take the ownership of the offer. |
| 3622 | SetRemoteDescriptionWithoutError(offer); |
| 3623 | |
| 3624 | SessionDescriptionInterface* answer = ChangeSDPSctpPort( |
| 3625 | new_recv_port, CreateAnswer(NULL)); |
| 3626 | ASSERT_TRUE(answer != NULL); |
| 3627 | |
| 3628 | // Now set the local description, which'll take ownership of the answer. |
| 3629 | SetLocalDescriptionWithoutError(answer); |
| 3630 | |
| 3631 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 3632 | // and pass it all the way down. |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 3633 | webrtc::InternalDataChannelInit dci; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3634 | dci.reliable = true; |
| 3635 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3636 | rtc::scoped_refptr<webrtc::DataChannel> dc = |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3637 | session_->CreateDataChannel("datachannel", &dci); |
| 3638 | |
| 3639 | cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0); |
| 3640 | int portnum = -1; |
| 3641 | ASSERT_TRUE(ch != NULL); |
| 3642 | ASSERT_EQ(1UL, ch->send_codecs().size()); |
| 3643 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3644 | EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3645 | ch->send_codecs()[0].name.c_str())); |
| 3646 | EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 3647 | &portnum)); |
| 3648 | EXPECT_EQ(new_send_port, portnum); |
| 3649 | |
| 3650 | ASSERT_EQ(1UL, ch->recv_codecs().size()); |
| 3651 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3652 | EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3653 | ch->recv_codecs()[0].name.c_str())); |
| 3654 | EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 3655 | &portnum)); |
| 3656 | EXPECT_EQ(new_recv_port, portnum); |
| 3657 | } |
| 3658 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3659 | TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) { |
| 3660 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
| 3661 | FakeDtlsIdentityStore::GenerateCertificate(); |
| 3662 | |
| 3663 | PeerConnectionInterface::RTCConfiguration configuration; |
| 3664 | configuration.certificates.push_back(certificate); |
| 3665 | Init(nullptr, configuration); |
| 3666 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
| 3667 | |
| 3668 | EXPECT_EQ(session_->certificate_for_testing(), certificate); |
| 3669 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3670 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3671 | // Verifies that CreateOffer succeeds when CreateOffer is called before async |
| 3672 | // identity generation is finished (even if a certificate is provided this is |
| 3673 | // an async op). |
| 3674 | TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { |
| 3675 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 3676 | InitWithDtls(GetParam()); |
| 3677 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3678 | EXPECT_TRUE(session_->waiting_for_certificate_for_testing()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3679 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3680 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 3681 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3682 | EXPECT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3683 | VerifyNoCryptoParams(offer->description(), true); |
| 3684 | VerifyFingerprintStatus(offer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | // Verifies that CreateAnswer succeeds when CreateOffer is called before async |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3688 | // identity generation is finished (even if a certificate is provided this is |
| 3689 | // an async op). |
| 3690 | TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3691 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3692 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3693 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3694 | |
| 3695 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3696 | options.recv_video = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3697 | scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3698 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3699 | ASSERT_TRUE(offer.get() != NULL); |
| 3700 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3701 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3702 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3703 | EXPECT_TRUE(answer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3704 | VerifyNoCryptoParams(answer->description(), true); |
| 3705 | VerifyFingerprintStatus(answer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | // Verifies that CreateOffer succeeds when CreateOffer is called after async |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3709 | // identity generation is finished (even if a certificate is provided this is |
| 3710 | // an async op). |
| 3711 | TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3712 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3713 | InitWithDtls(GetParam()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3714 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3715 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3716 | |
| 3717 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3718 | EXPECT_TRUE(offer != NULL); |
| 3719 | } |
| 3720 | |
| 3721 | // Verifies that CreateOffer fails when CreateOffer is called after async |
| 3722 | // identity generation fails. |
| 3723 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3724 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3725 | InitWithDtlsIdentityGenFail(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3726 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3727 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3728 | |
| 3729 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3730 | EXPECT_TRUE(offer == NULL); |
| 3731 | } |
| 3732 | |
| 3733 | // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made |
| 3734 | // before async identity generation is finished. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3735 | TEST_P(WebRtcSessionTest, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3736 | TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3737 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3738 | VerifyMultipleAsyncCreateDescription(GetParam(), |
| 3739 | CreateSessionDescriptionRequest::kOffer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | // Verifies that CreateOffer fails when Multiple CreateOffer calls are made |
| 3743 | // before async identity generation fails. |
| 3744 | TEST_F(WebRtcSessionTest, |
| 3745 | TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3746 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3747 | VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 3748 | CreateSessionDescriptionRequest::kOffer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | // Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made |
| 3752 | // before async identity generation is finished. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3753 | TEST_P(WebRtcSessionTest, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3754 | TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3755 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3756 | VerifyMultipleAsyncCreateDescription( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3757 | GetParam(), CreateSessionDescriptionRequest::kAnswer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | // Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made |
| 3761 | // before async identity generation fails. |
| 3762 | TEST_F(WebRtcSessionTest, |
| 3763 | TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3764 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3765 | VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 3766 | CreateSessionDescriptionRequest::kAnswer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3767 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 3768 | |
| 3769 | // Verifies that setRemoteDescription fails when DTLS is disabled and the remote |
| 3770 | // offer has no SDES crypto but only DTLS fingerprint. |
| 3771 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { |
| 3772 | // Init without DTLS. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3773 | Init(); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 3774 | // Create a remote offer with secured transport disabled. |
| 3775 | cricket::MediaSessionOptions options; |
| 3776 | JsepSessionDescription* offer(CreateRemoteOffer( |
| 3777 | options, cricket::SEC_DISABLED)); |
| 3778 | // Adds a DTLS fingerprint to the remote offer. |
| 3779 | cricket::SessionDescription* sdp = offer->description(); |
| 3780 | TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 3781 | ASSERT_TRUE(audio != NULL); |
| 3782 | ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); |
| 3783 | audio->description.identity_fingerprint.reset( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3784 | rtc::SSLFingerprint::CreateFromRfc4572( |
| 3785 | rtc::DIGEST_SHA_256, kFakeDtlsFingerprint)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3786 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3787 | offer); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3790 | // This test verifies DSCP is properly applied on the media channels. |
| 3791 | TEST_F(WebRtcSessionTest, TestDscpConstraint) { |
| 3792 | constraints_.reset(new FakeConstraints()); |
| 3793 | constraints_->AddOptional( |
| 3794 | webrtc::MediaConstraintsInterface::kEnableDscp, true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3795 | Init(); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3796 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3797 | SessionDescriptionInterface* offer = CreateOffer(); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3798 | |
| 3799 | SetLocalDescriptionWithoutError(offer); |
| 3800 | |
| 3801 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3802 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 3803 | |
| 3804 | ASSERT_TRUE(video_channel_ != NULL); |
| 3805 | ASSERT_TRUE(voice_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 3806 | const cricket::AudioOptions& audio_options = voice_channel_->options(); |
| 3807 | const cricket::VideoOptions& video_options = video_channel_->options(); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3808 | EXPECT_TRUE(audio_options.dscp.IsSet()); |
| 3809 | EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false)); |
| 3810 | EXPECT_TRUE(video_options.dscp.IsSet()); |
| 3811 | EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false)); |
| 3812 | } |
| 3813 | |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 3814 | TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) { |
| 3815 | constraints_.reset(new FakeConstraints()); |
| 3816 | constraints_->AddOptional( |
| 3817 | webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |
| 3818 | true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3819 | Init(); |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 3820 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3821 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 3822 | |
| 3823 | SetLocalDescriptionWithoutError(offer); |
| 3824 | |
| 3825 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3826 | |
| 3827 | ASSERT_TRUE(video_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 3828 | const cricket::VideoOptions& video_options = video_channel_->options(); |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 3829 | EXPECT_TRUE( |
| 3830 | video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false)); |
| 3831 | } |
| 3832 | |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 3833 | TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) { |
| 3834 | // Number of unsignalled receiving streams should be between 0 and |
| 3835 | // kMaxUnsignalledRecvStreams. |
| 3836 | SetAndVerifyNumUnsignalledRecvStreams(10, 10); |
| 3837 | SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1, |
| 3838 | kMaxUnsignalledRecvStreams); |
| 3839 | SetAndVerifyNumUnsignalledRecvStreams(-1, 0); |
| 3840 | } |
| 3841 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 3842 | TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { |
| 3843 | constraints_.reset(new FakeConstraints()); |
| 3844 | constraints_->AddOptional( |
| 3845 | webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe, |
| 3846 | true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3847 | Init(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 3848 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3849 | SessionDescriptionInterface* offer = CreateOffer(); |
| 3850 | |
| 3851 | SetLocalDescriptionWithoutError(offer); |
| 3852 | |
| 3853 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 3854 | |
| 3855 | ASSERT_TRUE(voice_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 3856 | const cricket::AudioOptions& audio_options = voice_channel_->options(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 3857 | EXPECT_TRUE( |
| 3858 | audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false)); |
| 3859 | } |
| 3860 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3861 | // Tests that we can renegotiate new media content with ICE candidates in the |
| 3862 | // new remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3863 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3864 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3865 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3866 | SetFactoryDtlsSrtp(); |
| 3867 | |
| 3868 | mediastream_signaling_.UseOptionsAudioOnly(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3869 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3870 | SetLocalDescriptionWithoutError(offer); |
| 3871 | |
| 3872 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3873 | SetRemoteDescriptionWithoutError(answer); |
| 3874 | |
| 3875 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3876 | options.recv_video = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3877 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 3878 | |
| 3879 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3880 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3881 | candidate1.set_component(1); |
| 3882 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 3883 | candidate1); |
| 3884 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 3885 | SetRemoteDescriptionWithoutError(offer); |
| 3886 | |
| 3887 | answer = CreateAnswer(NULL); |
| 3888 | SetLocalDescriptionWithoutError(answer); |
| 3889 | } |
| 3890 | |
| 3891 | // Tests that we can renegotiate new media content with ICE candidates separated |
| 3892 | // from the remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3893 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3894 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3895 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3896 | SetFactoryDtlsSrtp(); |
| 3897 | |
| 3898 | mediastream_signaling_.UseOptionsAudioOnly(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3899 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3900 | SetLocalDescriptionWithoutError(offer); |
| 3901 | |
| 3902 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3903 | SetRemoteDescriptionWithoutError(answer); |
| 3904 | |
| 3905 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3906 | options.recv_video = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3907 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 3908 | SetRemoteDescriptionWithoutError(offer); |
| 3909 | |
| 3910 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3911 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3912 | candidate1.set_component(1); |
| 3913 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 3914 | candidate1); |
| 3915 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate)); |
| 3916 | |
| 3917 | answer = CreateAnswer(NULL); |
| 3918 | SetLocalDescriptionWithoutError(answer); |
| 3919 | } |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3920 | // Tests that RTX codec is removed from the answer when it isn't supported |
| 3921 | // by local side. |
| 3922 | TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) { |
| 3923 | Init(); |
| 3924 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3925 | std::string offer_sdp(kSdpWithRtx); |
| 3926 | |
| 3927 | SessionDescriptionInterface* offer = |
| 3928 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL); |
| 3929 | EXPECT_TRUE(offer->ToString(&offer_sdp)); |
| 3930 | |
| 3931 | // Offer SDP contains the RTX codec. |
| 3932 | EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos); |
| 3933 | SetRemoteDescriptionWithoutError(offer); |
| 3934 | |
| 3935 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
| 3936 | std::string answer_sdp; |
| 3937 | answer->ToString(&answer_sdp); |
| 3938 | // Answer SDP removes the unsupported RTX codec. |
| 3939 | EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos); |
| 3940 | SetLocalDescriptionWithoutError(answer); |
| 3941 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3942 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3943 | // This verifies that the voice channel after bundle has both options from video |
| 3944 | // and voice channels. |
| 3945 | TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { |
| 3946 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
| 3947 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3948 | |
| 3949 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3950 | options.use_rtp_mux = true; |
| 3951 | |
| 3952 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3953 | SetLocalDescriptionWithoutError(offer); |
| 3954 | |
| 3955 | session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 3956 | rtc::Socket::Option::OPT_SNDBUF, 4000); |
| 3957 | |
| 3958 | session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 3959 | rtc::Socket::Option::OPT_RCVBUF, 8000); |
| 3960 | |
| 3961 | int option_val; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3962 | EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3963 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 3964 | EXPECT_EQ(4000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3965 | EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3966 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 3967 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3968 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3969 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3970 | EXPECT_EQ(8000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3971 | EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3972 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3973 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3974 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3975 | session_->video_rtp_transport_channel()); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3976 | |
| 3977 | mediastream_signaling_.SendAudioVideoStream2(); |
| 3978 | SessionDescriptionInterface* answer = |
| 3979 | CreateRemoteAnswer(session_->local_description()); |
| 3980 | SetRemoteDescriptionWithoutError(answer); |
| 3981 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3982 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3983 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 3984 | EXPECT_EQ(4000, option_val); |
| 3985 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3986 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3987 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3988 | EXPECT_EQ(8000, option_val); |
| 3989 | } |
| 3990 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 3991 | // Test creating a session, request multiple offers, destroy the session |
| 3992 | // and make sure we got success/failure callbacks for all of the requests. |
| 3993 | // Background: crbug.com/507307 |
| 3994 | TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { |
| 3995 | Init(); |
| 3996 | |
| 3997 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100]; |
| 3998 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3999 | options.offer_to_receive_audio = |
| 4000 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 4001 | |
| 4002 | for (auto& o : observers) { |
| 4003 | o = new WebRtcSessionCreateSDPObserverForTest(); |
| 4004 | session_->CreateOffer(o, options); |
| 4005 | } |
| 4006 | |
| 4007 | session_.reset(); |
| 4008 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4009 | for (auto& o : observers) { |
| 4010 | // We expect to have received a notification now even if the session was |
| 4011 | // terminated. The offer creation may or may not have succeeded, but we |
| 4012 | // must have received a notification which, so the only invalid state |
| 4013 | // is kInit. |
| 4014 | EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); |
| 4015 | } |
| 4016 | } |
| 4017 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4018 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 4019 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 4020 | // called more than once without returning to IceGatheringGathering. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4021 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4022 | INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 4023 | WebRtcSessionTest, |
| 4024 | testing::Values(ALREADY_GENERATED, |
| 4025 | DTLS_IDENTITY_STORE)); |