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