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