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