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