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