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