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