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