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