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