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