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