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