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)), |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 312 | stun_server_(Thread::Current(), stun_socket_addr_), |
| 313 | turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 314 | mediastream_signaling_(channel_manager_.get()), |
| 315 | ice_type_(PeerConnectionInterface::kAll) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID); |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 317 | |
| 318 | cricket::ServerAddresses stun_servers; |
| 319 | stun_servers.insert(stun_socket_addr_); |
| 320 | allocator_.reset(new cricket::BasicPortAllocator( |
| 321 | &network_manager_, |
| 322 | stun_servers, |
| 323 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 324 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 326 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 327 | EXPECT_TRUE(channel_manager_->Init()); |
| 328 | desc_factory_->set_add_legacy_streams(false); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 329 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | } |
| 331 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 332 | static void SetUpTestCase() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 333 | rtc::InitializeSSL(); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static void TearDownTestCase() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 337 | rtc::CleanupSSL(); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 338 | } |
| 339 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 340 | void AddInterface(const SocketAddress& addr) { |
| 341 | network_manager_.AddInterface(addr); |
| 342 | } |
| 343 | |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 344 | void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) { |
| 345 | ice_type_ = type; |
| 346 | } |
| 347 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 348 | void Init(DTLSIdentityServiceInterface* identity_service) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | ASSERT_TRUE(session_.get() == NULL); |
| 350 | session_.reset(new WebRtcSessionForTest( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 351 | channel_manager_.get(), rtc::Thread::Current(), |
| 352 | rtc::Thread::Current(), allocator_.get(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 353 | &observer_, |
| 354 | &mediastream_signaling_)); |
| 355 | |
| 356 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 357 | observer_.ice_connection_state_); |
| 358 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 359 | observer_.ice_gathering_state_); |
| 360 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 361 | EXPECT_TRUE(session_->Initialize(options_, constraints_.get(), |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 362 | identity_service, ice_type_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void InitWithDtmfCodec() { |
| 366 | // Add kTelephoneEventCodec for dtmf test. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 367 | const cricket::AudioCodec kTelephoneEventCodec( |
| 368 | 106, "telephone-event", 8000, 0, 1, 0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 369 | std::vector<cricket::AudioCodec> codecs; |
| 370 | codecs.push_back(kTelephoneEventCodec); |
| 371 | media_engine_->SetAudioCodecs(codecs); |
| 372 | desc_factory_->set_audio_codecs(codecs); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 373 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 374 | } |
| 375 | |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 376 | void InitWithDtls(bool identity_request_should_fail = false) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 377 | FakeIdentityService* identity_service = new FakeIdentityService(); |
| 378 | identity_service->set_should_fail(identity_request_should_fail); |
| 379 | Init(identity_service); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Creates a local offer and applies it. Starts ice. |
| 383 | // Call mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 384 | // to decide which streams to create. |
| 385 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 386 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 387 | SetLocalDescriptionWithoutError(offer); |
| 388 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 389 | observer_.ice_gathering_state_, |
| 390 | kIceCandidatesTimeout); |
| 391 | } |
| 392 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 393 | SessionDescriptionInterface* CreateOffer() { |
| 394 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 395 | options.offer_to_receive_audio = |
| 396 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 397 | |
| 398 | return CreateOffer(options); |
| 399 | } |
| 400 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 401 | SessionDescriptionInterface* CreateOffer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 402 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 403 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 404 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 405 | session_->CreateOffer(observer, options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 406 | EXPECT_TRUE_WAIT( |
| 407 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 408 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 409 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | SessionDescriptionInterface* CreateAnswer( |
| 413 | const webrtc::MediaConstraintsInterface* constraints) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 414 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 415 | = new WebRtcSessionCreateSDPObserverForTest(); |
| 416 | session_->CreateAnswer(observer, constraints); |
| 417 | EXPECT_TRUE_WAIT( |
| 418 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 419 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 420 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 421 | } |
| 422 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 423 | bool ChannelsExist() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | return (session_->voice_channel() != NULL && |
| 425 | session_->video_channel() != NULL); |
| 426 | } |
| 427 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 428 | void CheckTransportChannels() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 429 | EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL); |
| 430 | EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL); |
| 431 | EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL); |
| 432 | EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL); |
| 433 | } |
| 434 | |
| 435 | void VerifyCryptoParams(const cricket::SessionDescription* sdp) { |
| 436 | ASSERT_TRUE(session_.get() != NULL); |
| 437 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 438 | ASSERT_TRUE(content != NULL); |
| 439 | const cricket::AudioContentDescription* audio_content = |
| 440 | static_cast<const cricket::AudioContentDescription*>( |
| 441 | content->description); |
| 442 | ASSERT_TRUE(audio_content != NULL); |
| 443 | ASSERT_EQ(1U, audio_content->cryptos().size()); |
| 444 | ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); |
| 445 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 446 | audio_content->cryptos()[0].cipher_suite); |
| 447 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 448 | audio_content->protocol()); |
| 449 | |
| 450 | content = cricket::GetFirstVideoContent(sdp); |
| 451 | ASSERT_TRUE(content != NULL); |
| 452 | const cricket::VideoContentDescription* video_content = |
| 453 | static_cast<const cricket::VideoContentDescription*>( |
| 454 | content->description); |
| 455 | ASSERT_TRUE(video_content != NULL); |
| 456 | ASSERT_EQ(1U, video_content->cryptos().size()); |
| 457 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 458 | video_content->cryptos()[0].cipher_suite); |
| 459 | ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); |
| 460 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 461 | video_content->protocol()); |
| 462 | } |
| 463 | |
| 464 | void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { |
| 465 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 466 | ASSERT_TRUE(content != NULL); |
| 467 | const cricket::AudioContentDescription* audio_content = |
| 468 | static_cast<const cricket::AudioContentDescription*>( |
| 469 | content->description); |
| 470 | ASSERT_TRUE(audio_content != NULL); |
| 471 | ASSERT_EQ(0U, audio_content->cryptos().size()); |
| 472 | |
| 473 | content = cricket::GetFirstVideoContent(sdp); |
| 474 | ASSERT_TRUE(content != NULL); |
| 475 | const cricket::VideoContentDescription* video_content = |
| 476 | static_cast<const cricket::VideoContentDescription*>( |
| 477 | content->description); |
| 478 | ASSERT_TRUE(video_content != NULL); |
| 479 | ASSERT_EQ(0U, video_content->cryptos().size()); |
| 480 | |
| 481 | if (dtls) { |
| 482 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 483 | audio_content->protocol()); |
| 484 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 485 | video_content->protocol()); |
| 486 | } else { |
| 487 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 488 | audio_content->protocol()); |
| 489 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 490 | video_content->protocol()); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | // Set the internal fake description factories to do DTLS-SRTP. |
| 495 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 496 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 498 | rtc::ToString(rtc::CreateRandomId()); |
| 499 | identity_.reset(rtc::SSLIdentity::Generate(identity_name)); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 500 | tdesc_factory_->set_identity(identity_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 501 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 502 | } |
| 503 | |
| 504 | void VerifyFingerprintStatus(const cricket::SessionDescription* sdp, |
| 505 | bool expected) { |
| 506 | const TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 507 | ASSERT_TRUE(audio != NULL); |
| 508 | ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | const TransportInfo* video = sdp->GetTransportInfoByName("video"); |
| 510 | ASSERT_TRUE(video != NULL); |
| 511 | ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | void VerifyAnswerFromNonCryptoOffer() { |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 515 | // Create a SDP without Crypto. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 516 | cricket::MediaSessionOptions options; |
| 517 | options.has_video = true; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 518 | JsepSessionDescription* offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 519 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 520 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | VerifyNoCryptoParams(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 522 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
| 523 | offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 524 | const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 525 | // Answer should be NULL as no crypto params in offer. |
| 526 | ASSERT_TRUE(answer == NULL); |
| 527 | } |
| 528 | |
| 529 | void VerifyAnswerFromCryptoOffer() { |
| 530 | cricket::MediaSessionOptions options; |
| 531 | options.has_video = true; |
| 532 | options.bundle_enabled = true; |
| 533 | scoped_ptr<JsepSessionDescription> offer( |
| 534 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 535 | ASSERT_TRUE(offer.get() != NULL); |
| 536 | VerifyCryptoParams(offer->description()); |
| 537 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 538 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 539 | ASSERT_TRUE(answer.get() != NULL); |
| 540 | VerifyCryptoParams(answer->description()); |
| 541 | } |
| 542 | |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 543 | void SetAndVerifyNumUnsignalledRecvStreams( |
| 544 | int value_set, int value_expected) { |
| 545 | constraints_.reset(new FakeConstraints()); |
| 546 | constraints_->AddOptional( |
| 547 | webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams, |
| 548 | value_set); |
| 549 | session_.reset(); |
| 550 | Init(NULL); |
| 551 | mediastream_signaling_.SendAudioVideoStream1(); |
| 552 | SessionDescriptionInterface* offer = CreateOffer(); |
| 553 | |
| 554 | SetLocalDescriptionWithoutError(offer); |
| 555 | |
| 556 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 557 | |
| 558 | ASSERT_TRUE(video_channel_ != NULL); |
| 559 | cricket::VideoOptions video_options; |
| 560 | EXPECT_TRUE(video_channel_->GetOptions(&video_options)); |
| 561 | EXPECT_EQ(value_expected, |
| 562 | video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1)); |
| 563 | } |
| 564 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 565 | void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1, |
| 566 | const cricket::SessionDescription* desc2, |
| 567 | bool expect_equal) { |
| 568 | if (desc1->contents().size() != desc2->contents().size()) { |
| 569 | EXPECT_FALSE(expect_equal); |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | const cricket::ContentInfos& contents = desc1->contents(); |
| 574 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 575 | |
| 576 | for (; it != contents.end(); ++it) { |
| 577 | const cricket::TransportDescription* transport_desc1 = |
| 578 | desc1->GetTransportDescriptionByName(it->name); |
| 579 | const cricket::TransportDescription* transport_desc2 = |
| 580 | desc2->GetTransportDescriptionByName(it->name); |
| 581 | if (!transport_desc1 || !transport_desc2) { |
| 582 | EXPECT_FALSE(expect_equal); |
| 583 | return; |
| 584 | } |
| 585 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 586 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 587 | EXPECT_FALSE(expect_equal); |
| 588 | return; |
| 589 | } |
| 590 | } |
| 591 | EXPECT_TRUE(expect_equal); |
| 592 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 593 | |
| 594 | void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 595 | std::string *sdp) { |
| 596 | const cricket::SessionDescription* desc = current_desc->description(); |
| 597 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 598 | |
| 599 | const cricket::ContentInfos& contents = desc->contents(); |
| 600 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 601 | // Replace ufrag and pwd lines with empty strings. |
| 602 | for (; it != contents.end(); ++it) { |
| 603 | const cricket::TransportDescription* transport_desc = |
| 604 | desc->GetTransportDescriptionByName(it->name); |
| 605 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 606 | + "\r\n"; |
| 607 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 608 | + "\r\n"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 609 | rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 610 | "", 0, |
| 611 | sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 612 | rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 613 | "", 0, |
| 614 | sdp); |
| 615 | } |
| 616 | } |
| 617 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 618 | void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 619 | const std::string& modified_ice_ufrag, |
| 620 | const std::string& modified_ice_pwd, |
| 621 | std::string* sdp) { |
| 622 | const cricket::SessionDescription* desc = current_desc->description(); |
| 623 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 624 | |
| 625 | const cricket::ContentInfos& contents = desc->contents(); |
| 626 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 627 | // Replace ufrag and pwd lines with |modified_ice_ufrag| and |
| 628 | // |modified_ice_pwd| strings. |
| 629 | for (; it != contents.end(); ++it) { |
| 630 | const cricket::TransportDescription* transport_desc = |
| 631 | desc->GetTransportDescriptionByName(it->name); |
| 632 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 633 | + "\r\n"; |
| 634 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 635 | + "\r\n"; |
| 636 | std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n"; |
| 637 | 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] | 638 | rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 639 | mod_ufrag.c_str(), mod_ufrag.length(), |
| 640 | sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 641 | rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 642 | mod_pwd.c_str(), mod_pwd.length(), |
| 643 | sdp); |
| 644 | } |
| 645 | } |
| 646 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 647 | // Creates a remote offer and and applies it as a remote description, |
| 648 | // creates a local answer and applies is as a local description. |
| 649 | // Call mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 650 | // to decide which local and remote streams to create. |
| 651 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 652 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 653 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 654 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 655 | SetLocalDescriptionWithoutError(answer); |
| 656 | } |
| 657 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 658 | EXPECT_TRUE(session_->SetLocalDescription(desc, NULL)); |
| 659 | } |
| 660 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
| 661 | BaseSession::State expected_state) { |
| 662 | SetLocalDescriptionWithoutError(desc); |
| 663 | EXPECT_EQ(expected_state, session_->state()); |
| 664 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 665 | void SetLocalDescriptionExpectError(const std::string& action, |
| 666 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | SessionDescriptionInterface* desc) { |
| 668 | std::string error; |
| 669 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 670 | std::string sdp_type = "local "; |
| 671 | sdp_type.append(action); |
| 672 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 673 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 674 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 675 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 676 | SessionDescriptionInterface* desc) { |
| 677 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 678 | expected_error, desc); |
| 679 | } |
| 680 | void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, |
| 681 | SessionDescriptionInterface* desc) { |
| 682 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 683 | expected_error, desc); |
| 684 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 685 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 686 | EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL)); |
| 687 | } |
| 688 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
| 689 | BaseSession::State expected_state) { |
| 690 | SetRemoteDescriptionWithoutError(desc); |
| 691 | EXPECT_EQ(expected_state, session_->state()); |
| 692 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 693 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 694 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 695 | SessionDescriptionInterface* desc) { |
| 696 | std::string error; |
| 697 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 698 | std::string sdp_type = "remote "; |
| 699 | sdp_type.append(action); |
| 700 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 701 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 702 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 703 | void SetRemoteDescriptionOfferExpectError( |
| 704 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 705 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 706 | expected_error, desc); |
| 707 | } |
| 708 | void SetRemoteDescriptionPranswerExpectError( |
| 709 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 710 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer, |
| 711 | expected_error, desc); |
| 712 | } |
| 713 | void SetRemoteDescriptionAnswerExpectError( |
| 714 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 715 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 716 | expected_error, desc); |
| 717 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 718 | |
| 719 | void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer, |
| 720 | SessionDescriptionInterface** nocrypto_answer) { |
| 721 | // Create a SDP without Crypto. |
| 722 | cricket::MediaSessionOptions options; |
| 723 | options.has_video = true; |
| 724 | options.bundle_enabled = true; |
| 725 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 726 | ASSERT_TRUE(*offer != NULL); |
| 727 | VerifyCryptoParams((*offer)->description()); |
| 728 | |
| 729 | *nocrypto_answer = CreateRemoteAnswer(*offer, options, |
| 730 | cricket::SEC_DISABLED); |
| 731 | EXPECT_TRUE(*nocrypto_answer != NULL); |
| 732 | } |
| 733 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 734 | void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer, |
| 735 | SessionDescriptionInterface** nodtls_answer) { |
| 736 | cricket::MediaSessionOptions options; |
| 737 | options.has_video = true; |
| 738 | options.bundle_enabled = true; |
| 739 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 740 | rtc::scoped_ptr<SessionDescriptionInterface> temp_offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 741 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
| 742 | |
| 743 | *nodtls_answer = |
| 744 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
| 745 | EXPECT_TRUE(*nodtls_answer != NULL); |
| 746 | VerifyFingerprintStatus((*nodtls_answer)->description(), false); |
| 747 | VerifyCryptoParams((*nodtls_answer)->description()); |
| 748 | |
| 749 | SetFactoryDtlsSrtp(); |
| 750 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 751 | ASSERT_TRUE(*offer != NULL); |
| 752 | VerifyFingerprintStatus((*offer)->description(), true); |
| 753 | VerifyCryptoParams((*offer)->description()); |
| 754 | } |
| 755 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 756 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 757 | cricket::MediaSessionOptions options, |
| 758 | cricket::SecurePolicy secure_policy, |
| 759 | const std::string& session_version, |
| 760 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 761 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 762 | const cricket::SessionDescription* cricket_desc = NULL; |
| 763 | if (current_desc) { |
| 764 | cricket_desc = current_desc->description(); |
| 765 | session_id = current_desc->session_id(); |
| 766 | } |
| 767 | |
| 768 | desc_factory_->set_secure(secure_policy); |
| 769 | JsepSessionDescription* offer( |
| 770 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 771 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 772 | session_id, session_version)) { |
| 773 | delete offer; |
| 774 | offer = NULL; |
| 775 | } |
| 776 | return offer; |
| 777 | } |
| 778 | JsepSessionDescription* CreateRemoteOffer( |
| 779 | cricket::MediaSessionOptions options) { |
| 780 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 781 | kSessionVersion, NULL); |
| 782 | } |
| 783 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 784 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 785 | return CreateRemoteOfferWithVersion( |
| 786 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 787 | } |
| 788 | JsepSessionDescription* CreateRemoteOffer( |
| 789 | cricket::MediaSessionOptions options, |
| 790 | const SessionDescriptionInterface* current_desc) { |
| 791 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 792 | kSessionVersion, current_desc); |
| 793 | } |
| 794 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 795 | JsepSessionDescription* CreateRemoteOfferWithSctpPort( |
| 796 | const char* sctp_stream_name, int new_port, |
| 797 | cricket::MediaSessionOptions options) { |
| 798 | options.data_channel_type = cricket::DCT_SCTP; |
| 799 | options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel", |
| 800 | sctp_stream_name); |
| 801 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 802 | } |
| 803 | |
| 804 | // Takes ownership of offer_basis (and deletes it). |
| 805 | JsepSessionDescription* ChangeSDPSctpPort( |
| 806 | int new_port, webrtc::SessionDescriptionInterface *offer_basis) { |
| 807 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 808 | // SessionDescription from the mutated string. |
| 809 | const char* default_port_str = "5000"; |
| 810 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 811 | 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] | 812 | std::string offer_str; |
| 813 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 814 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 815 | new_port_str, strlen(new_port_str), |
| 816 | &offer_str); |
| 817 | JsepSessionDescription* offer = new JsepSessionDescription( |
| 818 | offer_basis->type()); |
| 819 | delete offer_basis; |
| 820 | offer->Initialize(offer_str, NULL); |
| 821 | return offer; |
| 822 | } |
| 823 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 824 | // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX() |
| 825 | // before this function to decide which streams to create. |
| 826 | JsepSessionDescription* CreateRemoteOffer() { |
| 827 | cricket::MediaSessionOptions options; |
| 828 | mediastream_signaling_.GetOptionsForAnswer(NULL, &options); |
| 829 | return CreateRemoteOffer(options, session_->remote_description()); |
| 830 | } |
| 831 | |
| 832 | JsepSessionDescription* CreateRemoteAnswer( |
| 833 | const SessionDescriptionInterface* offer, |
| 834 | cricket::MediaSessionOptions options, |
| 835 | cricket::SecurePolicy policy) { |
| 836 | desc_factory_->set_secure(policy); |
| 837 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 838 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 839 | JsepSessionDescription* answer( |
| 840 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 841 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 842 | options, NULL), |
| 843 | session_id, kSessionVersion)) { |
| 844 | delete answer; |
| 845 | answer = NULL; |
| 846 | } |
| 847 | return answer; |
| 848 | } |
| 849 | |
| 850 | JsepSessionDescription* CreateRemoteAnswer( |
| 851 | const SessionDescriptionInterface* offer, |
| 852 | cricket::MediaSessionOptions options) { |
| 853 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 854 | } |
| 855 | |
| 856 | // Creates an answer session description with streams based on |
| 857 | // |mediastream_signaling_|. Call |
| 858 | // mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 859 | // to decide which streams to create. |
| 860 | JsepSessionDescription* CreateRemoteAnswer( |
| 861 | const SessionDescriptionInterface* offer) { |
| 862 | cricket::MediaSessionOptions options; |
| 863 | mediastream_signaling_.GetOptionsForAnswer(NULL, &options); |
| 864 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 865 | } |
| 866 | |
| 867 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 868 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 869 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 870 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 871 | |
| 872 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 873 | options.use_rtp_mux = bundle; |
| 874 | |
| 875 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 876 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 877 | // and answer. |
| 878 | SetLocalDescriptionWithoutError(offer); |
| 879 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 880 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 881 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | std::string sdp; |
| 883 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 884 | |
| 885 | size_t expected_candidate_num = 2; |
| 886 | if (!rtcp_mux) { |
| 887 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 888 | // for rtp and rtcp. |
| 889 | expected_candidate_num = 4; |
| 890 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 891 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 892 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 893 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 894 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 895 | &sdp); |
| 896 | } |
| 897 | |
| 898 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 899 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 900 | |
| 901 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 902 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 903 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 904 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
| 905 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
| 906 | for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) { |
| 907 | cricket::Candidate c0 = observer_.mline_0_candidates_[i]; |
| 908 | cricket::Candidate c1 = observer_.mline_1_candidates_[i]; |
| 909 | if (bundle) { |
| 910 | EXPECT_TRUE(c0.IsEquivalent(c1)); |
| 911 | } else { |
| 912 | EXPECT_FALSE(c0.IsEquivalent(c1)); |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | // Tests that we can only send DTMF when the dtmf codec is supported. |
| 917 | void TestCanInsertDtmf(bool can) { |
| 918 | if (can) { |
| 919 | InitWithDtmfCodec(); |
| 920 | } else { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 921 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 922 | } |
| 923 | mediastream_signaling_.SendAudioVideoStream1(); |
| 924 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 925 | EXPECT_FALSE(session_->CanInsertDtmf("")); |
| 926 | EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1)); |
| 927 | } |
| 928 | |
| 929 | // The method sets up a call from the session to itself, in a loopback |
| 930 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 931 | // disconnection, and then a permanent disconnection. |
| 932 | // 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] | 933 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 934 | // While running the call, this method also checks if the session goes through |
| 935 | // the correct sequence of ICE states when a connection is established, |
| 936 | // broken, and re-established. |
| 937 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 938 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 939 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 940 | // The Gathering state should go: New -> Gathering -> Completed. |
| 941 | void TestLoopbackCall() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 942 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 943 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 944 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 945 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 946 | |
| 947 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 948 | observer_.ice_gathering_state_); |
| 949 | SetLocalDescriptionWithoutError(offer); |
| 950 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 951 | observer_.ice_connection_state_); |
| 952 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
| 953 | observer_.ice_gathering_state_, |
| 954 | kIceCandidatesTimeout); |
| 955 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 956 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 957 | observer_.ice_gathering_state_, |
| 958 | kIceCandidatesTimeout); |
| 959 | |
| 960 | std::string sdp; |
| 961 | offer->ToString(&sdp); |
| 962 | SessionDescriptionInterface* desc = |
| 963 | webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp); |
| 964 | ASSERT_TRUE(desc != NULL); |
| 965 | SetRemoteDescriptionWithoutError(desc); |
| 966 | |
| 967 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
| 968 | observer_.ice_connection_state_, |
| 969 | kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 970 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 971 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 972 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 973 | observer_.ice_connection_state_, |
| 974 | kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 975 | |
| 976 | // Adding firewall rule to block ping requests, which should cause |
| 977 | // transport channel failure. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 978 | fss_->AddRule(false, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 979 | rtc::FP_ANY, |
| 980 | rtc::FD_ANY, |
| 981 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 982 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 983 | observer_.ice_connection_state_, |
| 984 | kIceCandidatesTimeout); |
| 985 | |
| 986 | // Clearing the rules, session should move back to completed state. |
| 987 | fss_->ClearRules(); |
| 988 | // Session is automatically calling OnSignalingReady after creation of |
| 989 | // new portallocator session which will allocate new set of candidates. |
| 990 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 991 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 992 | observer_.ice_connection_state_, |
| 993 | kIceCandidatesTimeout); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 994 | |
| 995 | // Now we block ping requests and wait until the ICE connection transitions |
| 996 | // to the Failed state. This will take at least 30 seconds because it must |
| 997 | // wait for the Port to timeout. |
| 998 | int port_timeout = 30000; |
| 999 | fss_->AddRule(false, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1000 | rtc::FP_ANY, |
| 1001 | rtc::FD_ANY, |
| 1002 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1003 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 1004 | observer_.ice_connection_state_, |
| 1005 | kIceCandidatesTimeout + port_timeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | void VerifyTransportType(const std::string& content_name, |
| 1009 | cricket::TransportProtocol protocol) { |
| 1010 | const cricket::Transport* transport = session_->GetTransport(content_name); |
| 1011 | ASSERT_TRUE(transport != NULL); |
| 1012 | EXPECT_EQ(protocol, transport->protocol()); |
| 1013 | } |
| 1014 | |
| 1015 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 1016 | void AddCNCodecs() { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1017 | const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0); |
| 1018 | const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0); |
| 1019 | |
| 1020 | // Add kCNCodec for dtmf test. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1021 | std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();; |
| 1022 | codecs.push_back(kCNCodec1); |
| 1023 | codecs.push_back(kCNCodec2); |
| 1024 | media_engine_->SetAudioCodecs(codecs); |
| 1025 | desc_factory_->set_audio_codecs(codecs); |
| 1026 | } |
| 1027 | |
| 1028 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 1029 | const cricket::ContentDescription* description = content->description; |
| 1030 | ASSERT(description != NULL); |
| 1031 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1032 | static_cast<const cricket::AudioContentDescription*>(description); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1033 | ASSERT(audio_content_desc != NULL); |
| 1034 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 1035 | if (audio_content_desc->codecs()[i].name == "CN") |
| 1036 | return false; |
| 1037 | } |
| 1038 | return true; |
| 1039 | } |
| 1040 | |
| 1041 | void SetLocalDescriptionWithDataChannel() { |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1042 | webrtc::InternalDataChannelInit dci; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1043 | dci.reliable = false; |
| 1044 | session_->CreateDataChannel("datachannel", &dci); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1045 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1046 | SetLocalDescriptionWithoutError(offer); |
| 1047 | } |
| 1048 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1049 | void VerifyMultipleAsyncCreateDescription( |
| 1050 | bool success, CreateSessionDescriptionRequest::Type type) { |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 1051 | InitWithDtls(!success); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1052 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1053 | if (type == CreateSessionDescriptionRequest::kAnswer) { |
| 1054 | cricket::MediaSessionOptions options; |
| 1055 | scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1056 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1057 | ASSERT_TRUE(offer.get() != NULL); |
| 1058 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1059 | } |
| 1060 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1061 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1062 | const int kNumber = 3; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1063 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1064 | observers[kNumber]; |
| 1065 | for (int i = 0; i < kNumber; ++i) { |
| 1066 | observers[i] = new WebRtcSessionCreateSDPObserverForTest(); |
| 1067 | if (type == CreateSessionDescriptionRequest::kOffer) { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1068 | session_->CreateOffer(observers[i], options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1069 | } else { |
| 1070 | session_->CreateAnswer(observers[i], NULL); |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | WebRtcSessionCreateSDPObserverForTest::State expected_state = |
| 1075 | success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded : |
| 1076 | WebRtcSessionCreateSDPObserverForTest::kFailed; |
| 1077 | |
| 1078 | for (int i = 0; i < kNumber; ++i) { |
| 1079 | EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000); |
| 1080 | if (success) { |
| 1081 | EXPECT_TRUE(observers[i]->description() != NULL); |
| 1082 | } else { |
| 1083 | EXPECT_TRUE(observers[i]->description() == NULL); |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame^] | 1088 | void ConfigureAllocatorWithTurn() { |
| 1089 | cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
| 1090 | cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
| 1091 | relay_server.credentials = credentials; |
| 1092 | relay_server.ports.push_back(cricket::ProtocolAddress( |
| 1093 | kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
| 1094 | allocator_->AddRelay(relay_server); |
| 1095 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 1096 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 1097 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 1098 | } |
| 1099 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1100 | cricket::FakeMediaEngine* media_engine_; |
| 1101 | cricket::FakeDataEngine* data_engine_; |
| 1102 | cricket::FakeDeviceManager* device_manager_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1103 | rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; |
| 1104 | rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
| 1105 | rtc::scoped_ptr<rtc::SSLIdentity> identity_; |
| 1106 | rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
| 1107 | rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1108 | rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1109 | rtc::scoped_ptr<rtc::FirewallSocketServer> fss_; |
| 1110 | rtc::SocketServerScope ss_scope_; |
| 1111 | rtc::SocketAddress stun_socket_addr_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1112 | cricket::TestStunServer stun_server_; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1113 | cricket::TestTurnServer turn_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1114 | rtc::FakeNetworkManager network_manager_; |
| 1115 | rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1116 | PeerConnectionFactoryInterface::Options options_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1117 | rtc::scoped_ptr<FakeConstraints> constraints_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1118 | FakeMediaStreamSignaling mediastream_signaling_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1119 | rtc::scoped_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1120 | MockIceObserver observer_; |
| 1121 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1122 | cricket::FakeVoiceMediaChannel* voice_channel_; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1123 | PeerConnectionInterface::IceTransportsType ice_type_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1124 | }; |
| 1125 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1126 | TEST_F(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1127 | InitWithDtls(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1128 | // SDES is disabled when DTLS is on. |
| 1129 | EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1132 | TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1133 | Init(NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1134 | // SDES is required if DTLS is off. |
| 1135 | EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1138 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1139 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1140 | } |
| 1141 | |
| 1142 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1143 | // with rtcp-mux and/or bundle. |
| 1144 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1145 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1146 | } |
| 1147 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1148 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1149 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1150 | } |
| 1151 | |
| 1152 | TEST_F(WebRtcSessionTest, TestMultihomeCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1153 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1154 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1155 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1156 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1157 | InitiateCall(); |
| 1158 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1159 | EXPECT_EQ(8u, observer_.mline_0_candidates_.size()); |
| 1160 | EXPECT_EQ(8u, observer_.mline_1_candidates_.size()); |
| 1161 | } |
| 1162 | |
| 1163 | TEST_F(WebRtcSessionTest, TestStunError) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1164 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1165 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1166 | fss_->AddRule(false, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1167 | rtc::FP_UDP, |
| 1168 | rtc::FD_ANY, |
| 1169 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1170 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1171 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1172 | InitiateCall(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1173 | // Since kClientAddrHost1 is blocked, not expecting stun candidates for it. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1174 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1175 | EXPECT_EQ(6u, observer_.mline_0_candidates_.size()); |
| 1176 | EXPECT_EQ(6u, observer_.mline_1_candidates_.size()); |
| 1177 | } |
| 1178 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame^] | 1179 | // Test session delivers no candidates gathered when constraint set to "none". |
| 1180 | TEST_F(WebRtcSessionTest, TestIceTransportsNone) { |
| 1181 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1182 | SetIceTransportType(PeerConnectionInterface::kNone); |
| 1183 | Init(NULL); |
| 1184 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1185 | InitiateCall(); |
| 1186 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1187 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 1188 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 1189 | } |
| 1190 | |
| 1191 | // Test session delivers only relay candidates gathered when constaint set to |
| 1192 | // "relay". |
| 1193 | TEST_F(WebRtcSessionTest, TestIceTransportsRelay) { |
| 1194 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1195 | ConfigureAllocatorWithTurn(); |
| 1196 | SetIceTransportType(PeerConnectionInterface::kRelay); |
| 1197 | Init(NULL); |
| 1198 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1199 | InitiateCall(); |
| 1200 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1201 | EXPECT_EQ(2u, observer_.mline_0_candidates_.size()); |
| 1202 | EXPECT_EQ(2u, observer_.mline_1_candidates_.size()); |
| 1203 | for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) { |
| 1204 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 1205 | observer_.mline_0_candidates_[i].type()); |
| 1206 | } |
| 1207 | for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) { |
| 1208 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 1209 | observer_.mline_1_candidates_[i].type()); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | // Test session delivers all candidates gathered when constaint set to "all". |
| 1214 | TEST_F(WebRtcSessionTest, TestIceTransportsAll) { |
| 1215 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1216 | SetIceTransportType(PeerConnectionInterface::kAll); |
| 1217 | Init(NULL); |
| 1218 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1219 | InitiateCall(); |
| 1220 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1221 | // Host + STUN. By default allocator is disabled to gather relay candidates. |
| 1222 | EXPECT_EQ(4u, observer_.mline_0_candidates_.size()); |
| 1223 | EXPECT_EQ(4u, observer_.mline_1_candidates_.size()); |
| 1224 | } |
| 1225 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1226 | TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) { |
| 1227 | Init(NULL); |
| 1228 | SessionDescriptionInterface* offer = NULL; |
| 1229 | // Since |offer| is NULL, there's no way to tell if it's an offer or answer. |
| 1230 | std::string unknown_action; |
| 1231 | SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1232 | SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1233 | } |
| 1234 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1235 | // Test creating offers and receive answers and make sure the |
| 1236 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1237 | TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1238 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1239 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1240 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1241 | const std::string session_id_orig = offer->session_id(); |
| 1242 | const std::string session_version_orig = offer->session_version(); |
| 1243 | SetLocalDescriptionWithoutError(offer); |
| 1244 | |
| 1245 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1246 | SessionDescriptionInterface* answer = |
| 1247 | CreateRemoteAnswer(session_->local_description()); |
| 1248 | SetRemoteDescriptionWithoutError(answer); |
| 1249 | |
| 1250 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1251 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1252 | |
| 1253 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1254 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1255 | |
| 1256 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1257 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1258 | |
| 1259 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1260 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1261 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1262 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1263 | |
| 1264 | // Create new offer without send streams. |
| 1265 | mediastream_signaling_.SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1266 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1267 | |
| 1268 | // Verify the session id is the same and the session version is |
| 1269 | // increased. |
| 1270 | EXPECT_EQ(session_id_orig, offer->session_id()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1271 | EXPECT_LT(rtc::FromString<uint64>(session_version_orig), |
| 1272 | rtc::FromString<uint64>(offer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1273 | |
| 1274 | SetLocalDescriptionWithoutError(offer); |
| 1275 | |
| 1276 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1277 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1278 | SetRemoteDescriptionWithoutError(answer); |
| 1279 | |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 1280 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1281 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 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 | 52055a2 | 2014-09-04 17:12:25 +0000 | [diff] [blame] | 2056 | |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2057 | EXPECT_TRUE(content != NULL); |
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 | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2061 | // TODO(perkj): Should the direction be set to SEND_ONLY if |
| 2062 | // The constraints is set to not receive audio or video but a track is added? |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | // Test that an answer can not be created if the last remote description is not |
| 2066 | // an offer. |
| 2067 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2068 | Init(NULL); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2069 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2070 | SetLocalDescriptionWithoutError(offer); |
| 2071 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2072 | SetRemoteDescriptionWithoutError(answer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2073 | EXPECT_TRUE(CreateAnswer(NULL) == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | // Test that an answer contains the correct media content descriptions when no |
| 2077 | // constraints have been set. |
| 2078 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2079 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2080 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2081 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2082 | SetRemoteDescriptionWithoutError(offer.release()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2083 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2084 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2085 | const cricket::ContentInfo* content = |
| 2086 | cricket::GetFirstAudioContent(answer->description()); |
| 2087 | ASSERT_TRUE(content != NULL); |
| 2088 | EXPECT_FALSE(content->rejected); |
| 2089 | |
| 2090 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2091 | ASSERT_TRUE(content != NULL); |
| 2092 | EXPECT_FALSE(content->rejected); |
| 2093 | } |
| 2094 | |
| 2095 | // Test that an answer contains the correct media content descriptions when no |
| 2096 | // constraints have been set and the offer only contain audio. |
| 2097 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2098 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | // Create a remote offer with audio only. |
| 2100 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2101 | options.has_audio = true; |
| 2102 | options.has_video = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2103 | rtc::scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2104 | CreateRemoteOffer(options)); |
| 2105 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 2106 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 2107 | |
| 2108 | SetRemoteDescriptionWithoutError(offer.release()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2109 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2110 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2111 | const cricket::ContentInfo* content = |
| 2112 | cricket::GetFirstAudioContent(answer->description()); |
| 2113 | ASSERT_TRUE(content != NULL); |
| 2114 | EXPECT_FALSE(content->rejected); |
| 2115 | |
| 2116 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 2117 | } |
| 2118 | |
| 2119 | // Test that an answer contains the correct media content descriptions when no |
| 2120 | // constraints have been set. |
| 2121 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2122 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2123 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2124 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2125 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2126 | // Test with a stream with tracks. |
| 2127 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2128 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2129 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2130 | const cricket::ContentInfo* content = |
| 2131 | cricket::GetFirstAudioContent(answer->description()); |
| 2132 | ASSERT_TRUE(content != NULL); |
| 2133 | EXPECT_FALSE(content->rejected); |
| 2134 | |
| 2135 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2136 | ASSERT_TRUE(content != NULL); |
| 2137 | EXPECT_FALSE(content->rejected); |
| 2138 | } |
| 2139 | |
| 2140 | // Test that an answer contains the correct media content descriptions when |
| 2141 | // constraints have been set but no stream is sent. |
| 2142 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2143 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2144 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2145 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2146 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2147 | |
| 2148 | webrtc::FakeConstraints constraints_no_receive; |
| 2149 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 2150 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 2151 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2152 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2153 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2154 | const cricket::ContentInfo* content = |
| 2155 | cricket::GetFirstAudioContent(answer->description()); |
| 2156 | ASSERT_TRUE(content != NULL); |
| 2157 | EXPECT_TRUE(content->rejected); |
| 2158 | |
| 2159 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2160 | ASSERT_TRUE(content != NULL); |
| 2161 | EXPECT_TRUE(content->rejected); |
| 2162 | } |
| 2163 | |
| 2164 | // Test that an answer contains the correct media content descriptions when |
| 2165 | // constraints have been set and streams are sent. |
| 2166 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2167 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2168 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2169 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2170 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2171 | |
| 2172 | webrtc::FakeConstraints constraints_no_receive; |
| 2173 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 2174 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 2175 | |
| 2176 | // Test with a stream with tracks. |
| 2177 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2178 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2179 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2180 | |
| 2181 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2182 | const cricket::ContentInfo* content = |
| 2183 | cricket::GetFirstAudioContent(answer->description()); |
| 2184 | ASSERT_TRUE(content != NULL); |
| 2185 | EXPECT_FALSE(content->rejected); |
| 2186 | |
| 2187 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2188 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2189 | ASSERT_TRUE(content != NULL); |
| 2190 | EXPECT_FALSE(content->rejected); |
| 2191 | } |
| 2192 | |
| 2193 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 2194 | AddCNCodecs(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2195 | Init(NULL); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2196 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2197 | options.offer_to_receive_audio = |
| 2198 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2199 | options.voice_activity_detection = false; |
| 2200 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2201 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2202 | CreateOffer(options)); |
| 2203 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2204 | const cricket::ContentInfo* content = |
| 2205 | cricket::GetFirstAudioContent(offer->description()); |
| 2206 | EXPECT_TRUE(content != NULL); |
| 2207 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2208 | } |
| 2209 | |
| 2210 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 2211 | AddCNCodecs(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2212 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2213 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2214 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2215 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2216 | |
| 2217 | webrtc::FakeConstraints constraints; |
| 2218 | constraints.SetOptionalVAD(false); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2219 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2220 | CreateAnswer(&constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2221 | const cricket::ContentInfo* content = |
| 2222 | cricket::GetFirstAudioContent(answer->description()); |
| 2223 | ASSERT_TRUE(content != NULL); |
| 2224 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2225 | } |
| 2226 | |
| 2227 | // This test verifies the call setup when remote answer with audio only and |
| 2228 | // later updates with video. |
| 2229 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2230 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2231 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2232 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2233 | |
| 2234 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2235 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2236 | |
| 2237 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2238 | options.has_video = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2239 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 2240 | |
| 2241 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2242 | // and answer; |
| 2243 | SetLocalDescriptionWithoutError(offer); |
| 2244 | SetRemoteDescriptionWithoutError(answer); |
| 2245 | |
| 2246 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2247 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2248 | |
| 2249 | ASSERT_TRUE(video_channel_ == NULL); |
| 2250 | |
| 2251 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 2252 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2253 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 2254 | |
| 2255 | // Let the remote end update the session descriptions, with Audio and Video. |
| 2256 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2257 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2258 | |
| 2259 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2260 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2261 | |
| 2262 | ASSERT_TRUE(video_channel_ != NULL); |
| 2263 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2264 | |
| 2265 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2266 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2267 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2268 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2269 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2270 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2271 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2272 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2273 | |
| 2274 | // Change session back to audio only. |
| 2275 | mediastream_signaling_.UseOptionsAudioOnly(); |
| 2276 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2277 | |
| 2278 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2279 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2280 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2281 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2282 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2283 | } |
| 2284 | |
| 2285 | // This test verifies the call setup when remote answer with video only and |
| 2286 | // later updates with audio. |
| 2287 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2288 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2289 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2290 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2291 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2292 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2293 | |
| 2294 | cricket::MediaSessionOptions options; |
| 2295 | options.has_audio = false; |
| 2296 | options.has_video = true; |
| 2297 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2298 | offer, options, cricket::SEC_ENABLED); |
| 2299 | |
| 2300 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2301 | // and answer. |
| 2302 | SetLocalDescriptionWithoutError(offer); |
| 2303 | SetRemoteDescriptionWithoutError(answer); |
| 2304 | |
| 2305 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2306 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2307 | |
| 2308 | ASSERT_TRUE(voice_channel_ == NULL); |
| 2309 | ASSERT_TRUE(video_channel_ != NULL); |
| 2310 | |
| 2311 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2312 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2313 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 2314 | |
| 2315 | // Update the session descriptions, with Audio and Video. |
| 2316 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2317 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2318 | |
| 2319 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2320 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2321 | |
| 2322 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2323 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2324 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2325 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2326 | |
| 2327 | // Change session back to video only. |
| 2328 | mediastream_signaling_.UseOptionsVideoOnly(); |
| 2329 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2330 | |
| 2331 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2332 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2333 | |
| 2334 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2335 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2336 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2337 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2338 | } |
| 2339 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2340 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2341 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2342 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2343 | scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2344 | VerifyCryptoParams(offer->description()); |
| 2345 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2346 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2347 | VerifyCryptoParams(answer->description()); |
| 2348 | } |
| 2349 | |
| 2350 | TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2351 | options_.disable_encryption = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2352 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2353 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2354 | scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2355 | VerifyNoCryptoParams(offer->description(), false); |
| 2356 | } |
| 2357 | |
| 2358 | TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2359 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2360 | VerifyAnswerFromNonCryptoOffer(); |
| 2361 | } |
| 2362 | |
| 2363 | TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2364 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2365 | VerifyAnswerFromCryptoOffer(); |
| 2366 | } |
| 2367 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2368 | // This test verifies that setLocalDescription fails if |
| 2369 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2370 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) { |
| 2371 | Init(NULL); |
| 2372 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2373 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2374 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2375 | std::string sdp; |
| 2376 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2377 | SessionDescriptionInterface* modified_offer = |
| 2378 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2379 | SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | // This test verifies that setRemoteDescription fails if |
| 2383 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2384 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) { |
| 2385 | Init(NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2386 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2387 | std::string sdp; |
| 2388 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2389 | SessionDescriptionInterface* modified_offer = |
| 2390 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2391 | SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2394 | // This test verifies that setLocalDescription fails if local offer has |
| 2395 | // too short ice ufrag and pwd strings. |
| 2396 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) { |
| 2397 | Init(NULL); |
| 2398 | tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245); |
| 2399 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2400 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2401 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2402 | std::string sdp; |
| 2403 | // Modifying ice ufrag and pwd in local offer with strings smaller than the |
| 2404 | // recommended values of 4 and 22 bytes respectively. |
| 2405 | ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp); |
| 2406 | SessionDescriptionInterface* modified_offer = |
| 2407 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2408 | std::string error; |
| 2409 | EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error)); |
| 2410 | |
| 2411 | // Test with string greater than 256. |
| 2412 | sdp.clear(); |
| 2413 | ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd, |
| 2414 | &sdp); |
| 2415 | modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp, |
| 2416 | NULL); |
| 2417 | EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error)); |
| 2418 | } |
| 2419 | |
| 2420 | // This test verifies that setRemoteDescription fails if remote offer has |
| 2421 | // too short ice ufrag and pwd strings. |
| 2422 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) { |
| 2423 | Init(NULL); |
| 2424 | tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2425 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2426 | std::string sdp; |
| 2427 | // Modifying ice ufrag and pwd in remote offer with strings smaller than the |
| 2428 | // recommended values of 4 and 22 bytes respectively. |
| 2429 | ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp); |
| 2430 | SessionDescriptionInterface* modified_offer = |
| 2431 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2432 | std::string error; |
| 2433 | EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error)); |
| 2434 | |
| 2435 | sdp.clear(); |
| 2436 | ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd, |
| 2437 | &sdp); |
| 2438 | modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp, |
| 2439 | NULL); |
| 2440 | EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error)); |
| 2441 | } |
| 2442 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2443 | TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) { |
| 2444 | // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in |
| 2445 | // local description is removed by the application, BUNDLE flag should be |
| 2446 | // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2447 | Init(NULL); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 2448 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & |
| 2449 | allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2450 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2451 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2452 | cricket::SessionDescription* offer_copy = |
| 2453 | offer->description()->Copy(); |
| 2454 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2455 | JsepSessionDescription* modified_offer = |
| 2456 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2457 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 2458 | |
| 2459 | SetLocalDescriptionWithoutError(modified_offer); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 2460 | EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2464 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2465 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 2466 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & |
| 2467 | allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2468 | |
| 2469 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2470 | options.use_rtp_mux = true; |
| 2471 | |
| 2472 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2473 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2474 | SetLocalDescriptionWithoutError(offer); |
| 2475 | mediastream_signaling_.SendAudioVideoStream2(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2476 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2477 | CreateRemoteAnswer(session_->local_description())); |
| 2478 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2479 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2480 | JsepSessionDescription* modified_answer = |
| 2481 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2482 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2483 | SetRemoteDescriptionWithoutError(modified_answer); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 2484 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & |
| 2485 | allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2486 | |
| 2487 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2488 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2489 | |
| 2490 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2491 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 2492 | |
| 2493 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2494 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 2495 | |
| 2496 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2497 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 2498 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2499 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 2500 | } |
| 2501 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2502 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 2503 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 2504 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2505 | WebRtcSessionTest::Init(NULL); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2506 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 2507 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & |
| 2508 | allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2509 | |
| 2510 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2511 | options.use_rtp_mux = true; |
| 2512 | |
| 2513 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2514 | std::string offer_str; |
| 2515 | offer->ToString(&offer_str); |
| 2516 | // Disable rtcp-mux |
| 2517 | const std::string rtcp_mux = "rtcp-mux"; |
| 2518 | const std::string xrtcp_mux = "xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2519 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2520 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 2521 | &offer_str); |
| 2522 | JsepSessionDescription *local_offer = |
| 2523 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2524 | EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2525 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2526 | JsepSessionDescription *remote_offer = |
| 2527 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2528 | EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2529 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2530 | // Trying unmodified SDP. |
| 2531 | SetLocalDescriptionWithoutError(offer); |
| 2532 | } |
| 2533 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2534 | TEST_F(WebRtcSessionTest, SetAudioPlayout) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2535 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2536 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2537 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2538 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2539 | ASSERT_TRUE(channel != NULL); |
| 2540 | ASSERT_EQ(1u, channel->recv_streams().size()); |
| 2541 | uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
| 2542 | double left_vol, right_vol; |
| 2543 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2544 | EXPECT_EQ(1, left_vol); |
| 2545 | EXPECT_EQ(1, right_vol); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2546 | rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2547 | session_->SetAudioPlayout(receive_ssrc, false, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2548 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2549 | EXPECT_EQ(0, left_vol); |
| 2550 | EXPECT_EQ(0, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2551 | EXPECT_EQ(0, renderer->channel_id()); |
| 2552 | session_->SetAudioPlayout(receive_ssrc, true, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2553 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2554 | EXPECT_EQ(1, left_vol); |
| 2555 | EXPECT_EQ(1, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2556 | EXPECT_EQ(-1, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | TEST_F(WebRtcSessionTest, SetAudioSend) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2560 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2561 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2562 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2563 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2564 | ASSERT_TRUE(channel != NULL); |
| 2565 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2566 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2567 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2568 | |
| 2569 | cricket::AudioOptions options; |
| 2570 | options.echo_cancellation.Set(true); |
| 2571 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2572 | rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2573 | session_->SetAudioSend(send_ssrc, false, options, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2574 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 2575 | EXPECT_FALSE(channel->options().echo_cancellation.IsSet()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2576 | EXPECT_EQ(0, renderer->channel_id()); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 2577 | EXPECT_TRUE(renderer->sink() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2578 | |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 2579 | // This will trigger SetSink(NULL) to the |renderer|. |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2580 | session_->SetAudioSend(send_ssrc, true, options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2581 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2582 | bool value; |
| 2583 | EXPECT_TRUE(channel->options().echo_cancellation.Get(&value)); |
| 2584 | EXPECT_TRUE(value); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2585 | EXPECT_EQ(-1, renderer->channel_id()); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 2586 | EXPECT_TRUE(renderer->sink() == NULL); |
| 2587 | } |
| 2588 | |
| 2589 | TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) { |
| 2590 | Init(NULL); |
| 2591 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2592 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2593 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2594 | ASSERT_TRUE(channel != NULL); |
| 2595 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2596 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2597 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2598 | rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 2599 | cricket::AudioOptions options; |
| 2600 | session_->SetAudioSend(send_ssrc, true, options, renderer.get()); |
| 2601 | EXPECT_TRUE(renderer->sink() != NULL); |
| 2602 | |
| 2603 | // Delete the |renderer| and it will trigger OnClose() to the sink, and this |
| 2604 | // will invalidate the |renderer_| pointer in the sink and prevent getting a |
| 2605 | // SetSink(NULL) callback afterwards. |
| 2606 | renderer.reset(); |
| 2607 | |
| 2608 | // This will trigger SetSink(NULL) if no OnClose() callback. |
| 2609 | session_->SetAudioSend(send_ssrc, true, options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | TEST_F(WebRtcSessionTest, SetVideoPlayout) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2613 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2614 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2615 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2616 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 2617 | ASSERT_TRUE(channel != NULL); |
| 2618 | ASSERT_LT(0u, channel->renderers().size()); |
| 2619 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 2620 | ASSERT_EQ(1u, channel->recv_streams().size()); |
| 2621 | uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
| 2622 | cricket::FakeVideoRenderer renderer; |
| 2623 | session_->SetVideoPlayout(receive_ssrc, true, &renderer); |
| 2624 | EXPECT_TRUE(channel->renderers().begin()->second == &renderer); |
| 2625 | session_->SetVideoPlayout(receive_ssrc, false, &renderer); |
| 2626 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 2627 | } |
| 2628 | |
| 2629 | TEST_F(WebRtcSessionTest, SetVideoSend) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2630 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2631 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2632 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2633 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 2634 | ASSERT_TRUE(channel != NULL); |
| 2635 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2636 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2637 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2638 | cricket::VideoOptions* options = NULL; |
| 2639 | session_->SetVideoSend(send_ssrc, false, options); |
| 2640 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 2641 | session_->SetVideoSend(send_ssrc, true, options); |
| 2642 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2643 | } |
| 2644 | |
| 2645 | TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { |
| 2646 | TestCanInsertDtmf(false); |
| 2647 | } |
| 2648 | |
| 2649 | TEST_F(WebRtcSessionTest, CanInsertDtmf) { |
| 2650 | TestCanInsertDtmf(true); |
| 2651 | } |
| 2652 | |
| 2653 | TEST_F(WebRtcSessionTest, InsertDtmf) { |
| 2654 | // Setup |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2655 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2656 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2657 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2658 | FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2659 | EXPECT_EQ(0U, channel->dtmf_info_queue().size()); |
| 2660 | |
| 2661 | // Insert DTMF |
| 2662 | const int expected_flags = DF_SEND; |
| 2663 | const int expected_duration = 90; |
| 2664 | session_->InsertDtmf(kAudioTrack1, 0, expected_duration); |
| 2665 | session_->InsertDtmf(kAudioTrack1, 1, expected_duration); |
| 2666 | session_->InsertDtmf(kAudioTrack1, 2, expected_duration); |
| 2667 | |
| 2668 | // Verify |
| 2669 | ASSERT_EQ(3U, channel->dtmf_info_queue().size()); |
| 2670 | const uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2671 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0, |
| 2672 | expected_duration, expected_flags)); |
| 2673 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1, |
| 2674 | expected_duration, expected_flags)); |
| 2675 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2, |
| 2676 | expected_duration, expected_flags)); |
| 2677 | } |
| 2678 | |
| 2679 | // This test verifies the |initiator| flag when session initiates the call. |
| 2680 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2681 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2682 | EXPECT_FALSE(session_->initiator()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2683 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2684 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2685 | SetLocalDescriptionWithoutError(offer); |
| 2686 | EXPECT_TRUE(session_->initiator()); |
| 2687 | SetRemoteDescriptionWithoutError(answer); |
| 2688 | EXPECT_TRUE(session_->initiator()); |
| 2689 | } |
| 2690 | |
| 2691 | // This test verifies the |initiator| flag when session receives the call. |
| 2692 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2693 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2694 | EXPECT_FALSE(session_->initiator()); |
| 2695 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2696 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2697 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2698 | |
| 2699 | EXPECT_FALSE(session_->initiator()); |
| 2700 | SetLocalDescriptionWithoutError(answer); |
| 2701 | EXPECT_FALSE(session_->initiator()); |
| 2702 | } |
| 2703 | |
| 2704 | // This test verifies the ice protocol type at initiator of the call |
| 2705 | // if |a=ice-options:google-ice| is present in answer. |
| 2706 | TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2707 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2708 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2709 | SessionDescriptionInterface* offer = CreateOffer(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2710 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2711 | CreateRemoteAnswer(offer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2712 | SetLocalDescriptionWithoutError(offer); |
| 2713 | std::string sdp; |
| 2714 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2715 | // Adding ice-options to the session level. |
| 2716 | InjectAfter("t=0 0\r\n", |
| 2717 | "a=ice-options:google-ice\r\n", |
| 2718 | &sdp); |
| 2719 | SessionDescriptionInterface* answer_with_gice = |
| 2720 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2721 | SetRemoteDescriptionWithoutError(answer_with_gice); |
| 2722 | VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE); |
| 2723 | VerifyTransportType("video", cricket::ICEPROTO_GOOGLE); |
| 2724 | } |
| 2725 | |
| 2726 | // This test verifies the ice protocol type at initiator of the call |
| 2727 | // if ICE RFC5245 is supported in answer. |
| 2728 | TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2729 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2730 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2731 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2732 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2733 | SetLocalDescriptionWithoutError(offer); |
| 2734 | |
| 2735 | SetRemoteDescriptionWithoutError(answer); |
| 2736 | VerifyTransportType("audio", cricket::ICEPROTO_RFC5245); |
| 2737 | VerifyTransportType("video", cricket::ICEPROTO_RFC5245); |
| 2738 | } |
| 2739 | |
| 2740 | // This test verifies the ice protocol type at receiver side of the call if |
| 2741 | // receiver decides to use google-ice. |
| 2742 | TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2743 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2744 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2745 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2746 | SetRemoteDescriptionWithoutError(offer); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2747 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2748 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2749 | std::string sdp; |
| 2750 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2751 | // Adding ice-options to the session level. |
| 2752 | InjectAfter("t=0 0\r\n", |
| 2753 | "a=ice-options:google-ice\r\n", |
| 2754 | &sdp); |
| 2755 | SessionDescriptionInterface* answer_with_gice = |
| 2756 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2757 | SetLocalDescriptionWithoutError(answer_with_gice); |
| 2758 | VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE); |
| 2759 | VerifyTransportType("video", cricket::ICEPROTO_GOOGLE); |
| 2760 | } |
| 2761 | |
| 2762 | // This test verifies the ice protocol type at receiver side of the call if |
| 2763 | // receiver decides to use ice RFC 5245. |
| 2764 | TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2765 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2766 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2767 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2768 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2769 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2770 | SetLocalDescriptionWithoutError(answer); |
| 2771 | VerifyTransportType("audio", cricket::ICEPROTO_RFC5245); |
| 2772 | VerifyTransportType("video", cricket::ICEPROTO_RFC5245); |
| 2773 | } |
| 2774 | |
| 2775 | // This test verifies the session state when ICE RFC5245 in offer and |
| 2776 | // ICE google-ice in answer. |
| 2777 | TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2778 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2779 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2780 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2781 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2782 | std::string offer_str; |
| 2783 | offer->ToString(&offer_str); |
| 2784 | // Disable google-ice |
| 2785 | const std::string gice_option = "google-ice"; |
| 2786 | const std::string xgoogle_xice = "xgoogle-xice"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2787 | rtc::replace_substrs(gice_option.c_str(), gice_option.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2788 | xgoogle_xice.c_str(), xgoogle_xice.length(), |
| 2789 | &offer_str); |
| 2790 | JsepSessionDescription *ice_only_offer = |
| 2791 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2792 | EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL)); |
| 2793 | SetLocalDescriptionWithoutError(ice_only_offer); |
| 2794 | std::string original_offer_sdp; |
| 2795 | EXPECT_TRUE(offer->ToString(&original_offer_sdp)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2796 | SessionDescriptionInterface* pranswer_with_gice = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2797 | CreateSessionDescription(JsepSessionDescription::kPrAnswer, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2798 | original_offer_sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2799 | SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed, |
| 2800 | pranswer_with_gice); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2801 | SessionDescriptionInterface* answer_with_gice = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2802 | CreateSessionDescription(JsepSessionDescription::kAnswer, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2803 | original_offer_sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2804 | SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, |
| 2805 | answer_with_gice); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 2809 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2810 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2811 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2812 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2813 | SetLocalDescriptionWithoutError(offer); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2814 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2815 | CreateRemoteAnswer(session_->local_description())); |
| 2816 | |
| 2817 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2818 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2819 | JsepSessionDescription* modified_answer = |
| 2820 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2821 | |
| 2822 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2823 | answer->session_id(), |
| 2824 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2825 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2826 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2827 | // Different content names. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2828 | std::string sdp; |
| 2829 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2830 | const std::string kAudioMid = "a=mid:audio"; |
| 2831 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2832 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2833 | kAudioMidReplaceStr.c_str(), |
| 2834 | kAudioMidReplaceStr.length(), |
| 2835 | &sdp); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2836 | SessionDescriptionInterface* modified_answer1 = |
| 2837 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2838 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2839 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2840 | // Different media types. |
| 2841 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2842 | const std::string kAudioMline = "m=audio"; |
| 2843 | const std::string kAudioMlineReplaceStr = "m=video"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2844 | rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(), |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2845 | kAudioMlineReplaceStr.c_str(), |
| 2846 | kAudioMlineReplaceStr.length(), |
| 2847 | &sdp); |
| 2848 | SessionDescriptionInterface* modified_answer2 = |
| 2849 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2850 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2); |
| 2851 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2852 | SetRemoteDescriptionWithoutError(answer.release()); |
| 2853 | } |
| 2854 | |
| 2855 | // Verifying remote offer and local answer have matching m-lines as per |
| 2856 | // RFC 3264. |
| 2857 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2858 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2859 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2860 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2861 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2862 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2863 | |
| 2864 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2865 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2866 | JsepSessionDescription* modified_answer = |
| 2867 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2868 | |
| 2869 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2870 | answer->session_id(), |
| 2871 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2872 | SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2873 | SetLocalDescriptionWithoutError(answer); |
| 2874 | } |
| 2875 | |
| 2876 | // This test verifies that WebRtcSession does not start candidate allocation |
| 2877 | // before SetLocalDescription is called. |
| 2878 | TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2879 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2880 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2881 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2882 | cricket::Candidate candidate; |
| 2883 | candidate.set_component(1); |
| 2884 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2885 | candidate); |
| 2886 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2887 | cricket::Candidate candidate1; |
| 2888 | candidate1.set_component(1); |
| 2889 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2890 | candidate1); |
| 2891 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 2892 | SetRemoteDescriptionWithoutError(offer); |
| 2893 | ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL); |
| 2894 | ASSERT_TRUE(session_->GetTransportProxy("video") != NULL); |
| 2895 | |
| 2896 | // Pump for 1 second and verify that no candidates are generated. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2897 | rtc::Thread::Current()->ProcessMessages(1000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2898 | EXPECT_TRUE(observer_.mline_0_candidates_.empty()); |
| 2899 | EXPECT_TRUE(observer_.mline_1_candidates_.empty()); |
| 2900 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2901 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2902 | SetLocalDescriptionWithoutError(answer); |
| 2903 | EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated()); |
| 2904 | EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated()); |
| 2905 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 2906 | } |
| 2907 | |
| 2908 | // This test verifies that crypto parameter is updated in local session |
| 2909 | // description as per security policy set in MediaSessionDescriptionFactory. |
| 2910 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2911 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2912 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2913 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2914 | |
| 2915 | // Making sure SetLocalDescription correctly sets crypto value in |
| 2916 | // SessionDescription object after de-serialization of sdp string. The value |
| 2917 | // will be set as per MediaSessionDescriptionFactory. |
| 2918 | std::string offer_str; |
| 2919 | offer->ToString(&offer_str); |
| 2920 | SessionDescriptionInterface* jsep_offer_str = |
| 2921 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 2922 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 2923 | EXPECT_TRUE(session_->voice_channel()->secure_required()); |
| 2924 | EXPECT_TRUE(session_->video_channel()->secure_required()); |
| 2925 | } |
| 2926 | |
| 2927 | // This test verifies the crypto parameter when security is disabled. |
| 2928 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2929 | options_.disable_encryption = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2930 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2931 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2932 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2933 | |
| 2934 | // Making sure SetLocalDescription correctly sets crypto value in |
| 2935 | // SessionDescription object after de-serialization of sdp string. The value |
| 2936 | // will be set as per MediaSessionDescriptionFactory. |
| 2937 | std::string offer_str; |
| 2938 | offer->ToString(&offer_str); |
| 2939 | SessionDescriptionInterface *jsep_offer_str = |
| 2940 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 2941 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 2942 | EXPECT_FALSE(session_->voice_channel()->secure_required()); |
| 2943 | EXPECT_FALSE(session_->video_channel()->secure_required()); |
| 2944 | } |
| 2945 | |
| 2946 | // This test verifies that an answer contains new ufrag and password if an offer |
| 2947 | // with new ufrag and password is received. |
| 2948 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2949 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2950 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2951 | options.has_audio = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2952 | options.has_video = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2953 | rtc::scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2954 | CreateRemoteOffer(options)); |
| 2955 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2956 | |
| 2957 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2958 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2959 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2960 | SetLocalDescriptionWithoutError(answer.release()); |
| 2961 | |
| 2962 | // Receive an offer with new ufrag and password. |
| 2963 | options.transport_options.ice_restart = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2964 | rtc::scoped_ptr<JsepSessionDescription> updated_offer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2965 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2966 | SetRemoteDescriptionWithoutError(updated_offer1.release()); |
| 2967 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2968 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2969 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2970 | |
| 2971 | CompareIceUfragAndPassword(updated_answer1->description(), |
| 2972 | session_->local_description()->description(), |
| 2973 | false); |
| 2974 | |
| 2975 | SetLocalDescriptionWithoutError(updated_answer1.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2976 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2977 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2978 | // This test verifies that an answer contains old ufrag and password if an offer |
| 2979 | // with old ufrag and password is received. |
| 2980 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
| 2981 | Init(NULL); |
| 2982 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2983 | options.has_audio = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2984 | options.has_video = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2985 | rtc::scoped_ptr<JsepSessionDescription> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2986 | CreateRemoteOffer(options)); |
| 2987 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2988 | |
| 2989 | mediastream_signaling_.SendAudioVideoStream1(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2990 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2991 | CreateAnswer(NULL)); |
| 2992 | SetLocalDescriptionWithoutError(answer.release()); |
| 2993 | |
| 2994 | // Receive an offer without changed ufrag or password. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2995 | options.transport_options.ice_restart = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2996 | rtc::scoped_ptr<JsepSessionDescription> updated_offer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2997 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2998 | SetRemoteDescriptionWithoutError(updated_offer2.release()); |
| 2999 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3000 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3001 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3002 | |
| 3003 | CompareIceUfragAndPassword(updated_answer2->description(), |
| 3004 | session_->local_description()->description(), |
| 3005 | true); |
| 3006 | |
| 3007 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 3008 | } |
| 3009 | |
| 3010 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3011 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3012 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3013 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3014 | const std::string session_id_orig = offer->session_id(); |
| 3015 | const std::string session_version_orig = offer->session_version(); |
| 3016 | SetLocalDescriptionWithoutError(offer); |
| 3017 | |
| 3018 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3019 | video_channel_->set_fail_set_send_codecs(true); |
| 3020 | |
| 3021 | mediastream_signaling_.SendAudioVideoStream2(); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3022 | SessionDescriptionInterface* answer = |
| 3023 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3024 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 3028 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 3029 | // Lets try with only UDP ports. |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 3030 | allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3031 | cricket::PORTALLOCATOR_DISABLE_TCP | |
| 3032 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3033 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 3034 | TestLoopbackCall(); |
| 3035 | } |
| 3036 | |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 3037 | // Runs the loopback call test with BUNDLE and STUN enabled. |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3038 | TEST_F(WebRtcSessionTest, TestIceStatesBundle) { |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 3039 | allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3040 | cricket::PORTALLOCATOR_ENABLE_BUNDLE | |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 3041 | cricket::PORTALLOCATOR_DISABLE_TCP | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3042 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 3043 | TestLoopbackCall(); |
| 3044 | } |
| 3045 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3046 | TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3047 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3048 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 3049 | options.has_audio = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3050 | options.has_video = true; |
| 3051 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3052 | cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT; |
| 3053 | std::string error_code_str = "ERROR_CONTENT"; |
| 3054 | std::string error_desc = "Fake session error description."; |
| 3055 | session_->SetError(error_code, error_desc); |
| 3056 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3057 | SessionDescriptionInterface* offer = CreateRemoteOffer(options); |
| 3058 | SessionDescriptionInterface* answer = |
| 3059 | CreateRemoteAnswer(offer, options); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3060 | |
| 3061 | std::string action; |
| 3062 | std::ostringstream session_error_msg; |
| 3063 | session_error_msg << kSessionError << error_code_str << ". "; |
| 3064 | session_error_msg << kSessionErrorDesc << error_desc << "."; |
| 3065 | SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer); |
| 3066 | SetLocalDescriptionExpectError(action, session_error_msg.str(), answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
| 3070 | constraints_.reset(new FakeConstraints()); |
| 3071 | constraints_->AddOptional( |
| 3072 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3073 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3074 | |
| 3075 | SetLocalDescriptionWithDataChannel(); |
| 3076 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 3077 | } |
| 3078 | |
| 3079 | TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3080 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3081 | |
| 3082 | constraints_.reset(new FakeConstraints()); |
| 3083 | constraints_->AddOptional( |
| 3084 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3085 | options_.disable_sctp_data_channels = false; |
| 3086 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3087 | InitWithDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3088 | |
| 3089 | SetLocalDescriptionWithDataChannel(); |
| 3090 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 3091 | } |
| 3092 | |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 3093 | TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3094 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 3095 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3096 | InitWithDtls(); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3097 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3098 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3099 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3100 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 3101 | } |
| 3102 | |
| 3103 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3104 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3105 | SetFactoryDtlsSrtp(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3106 | InitWithDtls(); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3107 | |
| 3108 | // Create remote offer with SCTP. |
| 3109 | cricket::MediaSessionOptions options; |
| 3110 | options.data_channel_type = cricket::DCT_SCTP; |
| 3111 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3112 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3113 | SetRemoteDescriptionWithoutError(offer); |
| 3114 | |
| 3115 | // Verifies the answer contains SCTP. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3116 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3117 | EXPECT_TRUE(answer != NULL); |
| 3118 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 3119 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3122 | TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
| 3123 | constraints_.reset(new FakeConstraints()); |
| 3124 | constraints_->AddOptional( |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3125 | webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3126 | InitWithDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3127 | |
| 3128 | SetLocalDescriptionWithDataChannel(); |
| 3129 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 3130 | } |
| 3131 | |
| 3132 | TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3133 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3134 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3135 | InitWithDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3136 | |
| 3137 | SetLocalDescriptionWithDataChannel(); |
| 3138 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 3139 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3140 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3141 | TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3142 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3143 | options_.disable_sctp_data_channels = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3144 | InitWithDtls(); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3145 | |
| 3146 | SetLocalDescriptionWithDataChannel(); |
| 3147 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 3148 | } |
| 3149 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3150 | TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3151 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3152 | const int new_send_port = 9998; |
| 3153 | const int new_recv_port = 7775; |
| 3154 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3155 | InitWithDtls(); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3156 | SetFactoryDtlsSrtp(); |
| 3157 | |
| 3158 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 3159 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 3160 | // let the session description get parsed. That'll get the proper codecs |
| 3161 | // into the stream. |
| 3162 | cricket::MediaSessionOptions options; |
| 3163 | JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort( |
| 3164 | "stream1", new_send_port, options); |
| 3165 | |
| 3166 | // SetRemoteDescription will take the ownership of the offer. |
| 3167 | SetRemoteDescriptionWithoutError(offer); |
| 3168 | |
| 3169 | SessionDescriptionInterface* answer = ChangeSDPSctpPort( |
| 3170 | new_recv_port, CreateAnswer(NULL)); |
| 3171 | ASSERT_TRUE(answer != NULL); |
| 3172 | |
| 3173 | // Now set the local description, which'll take ownership of the answer. |
| 3174 | SetLocalDescriptionWithoutError(answer); |
| 3175 | |
| 3176 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 3177 | // and pass it all the way down. |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 3178 | webrtc::InternalDataChannelInit dci; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3179 | dci.reliable = true; |
| 3180 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3181 | rtc::scoped_refptr<webrtc::DataChannel> dc = |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3182 | session_->CreateDataChannel("datachannel", &dci); |
| 3183 | |
| 3184 | cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0); |
| 3185 | int portnum = -1; |
| 3186 | ASSERT_TRUE(ch != NULL); |
| 3187 | ASSERT_EQ(1UL, ch->send_codecs().size()); |
| 3188 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id); |
| 3189 | EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName, |
| 3190 | ch->send_codecs()[0].name.c_str())); |
| 3191 | EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 3192 | &portnum)); |
| 3193 | EXPECT_EQ(new_send_port, portnum); |
| 3194 | |
| 3195 | ASSERT_EQ(1UL, ch->recv_codecs().size()); |
| 3196 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id); |
| 3197 | EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName, |
| 3198 | ch->recv_codecs()[0].name.c_str())); |
| 3199 | EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 3200 | &portnum)); |
| 3201 | EXPECT_EQ(new_recv_port, portnum); |
| 3202 | } |
| 3203 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3204 | // Verifies that CreateOffer succeeds when CreateOffer is called before async |
| 3205 | // identity generation is finished. |
| 3206 | TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3207 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3208 | InitWithDtls(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3209 | |
| 3210 | EXPECT_TRUE(session_->waiting_for_identity()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3211 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3212 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 3213 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3214 | EXPECT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3215 | VerifyNoCryptoParams(offer->description(), true); |
| 3216 | VerifyFingerprintStatus(offer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | // Verifies that CreateAnswer succeeds when CreateOffer is called before async |
| 3220 | // identity generation is finished. |
| 3221 | TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3222 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3223 | InitWithDtls(); |
| 3224 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3225 | |
| 3226 | cricket::MediaSessionOptions options; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3227 | options.has_video = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3228 | scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3229 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3230 | ASSERT_TRUE(offer.get() != NULL); |
| 3231 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3232 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3233 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3234 | EXPECT_TRUE(answer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3235 | VerifyNoCryptoParams(answer->description(), true); |
| 3236 | VerifyFingerprintStatus(answer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | // Verifies that CreateOffer succeeds when CreateOffer is called after async |
| 3240 | // identity generation is finished. |
| 3241 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3242 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3243 | InitWithDtls(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3244 | |
| 3245 | EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3246 | |
| 3247 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3248 | EXPECT_TRUE(offer != NULL); |
| 3249 | } |
| 3250 | |
| 3251 | // Verifies that CreateOffer fails when CreateOffer is called after async |
| 3252 | // identity generation fails. |
| 3253 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3254 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 3255 | InitWithDtls(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3256 | |
| 3257 | EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3258 | |
| 3259 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3260 | EXPECT_TRUE(offer == NULL); |
| 3261 | } |
| 3262 | |
| 3263 | // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made |
| 3264 | // before async identity generation is finished. |
| 3265 | TEST_F(WebRtcSessionTest, |
| 3266 | TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3267 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3268 | VerifyMultipleAsyncCreateDescription( |
| 3269 | true, CreateSessionDescriptionRequest::kOffer); |
| 3270 | } |
| 3271 | |
| 3272 | // Verifies that CreateOffer fails when Multiple CreateOffer calls are made |
| 3273 | // before async identity generation fails. |
| 3274 | TEST_F(WebRtcSessionTest, |
| 3275 | TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3276 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3277 | VerifyMultipleAsyncCreateDescription( |
| 3278 | false, CreateSessionDescriptionRequest::kOffer); |
| 3279 | } |
| 3280 | |
| 3281 | // Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made |
| 3282 | // before async identity generation is finished. |
| 3283 | TEST_F(WebRtcSessionTest, |
| 3284 | TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3285 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3286 | VerifyMultipleAsyncCreateDescription( |
| 3287 | true, CreateSessionDescriptionRequest::kAnswer); |
| 3288 | } |
| 3289 | |
| 3290 | // Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made |
| 3291 | // before async identity generation fails. |
| 3292 | TEST_F(WebRtcSessionTest, |
| 3293 | TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3294 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3295 | VerifyMultipleAsyncCreateDescription( |
| 3296 | false, CreateSessionDescriptionRequest::kAnswer); |
| 3297 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 3298 | |
| 3299 | // Verifies that setRemoteDescription fails when DTLS is disabled and the remote |
| 3300 | // offer has no SDES crypto but only DTLS fingerprint. |
| 3301 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { |
| 3302 | // Init without DTLS. |
| 3303 | Init(NULL); |
| 3304 | // Create a remote offer with secured transport disabled. |
| 3305 | cricket::MediaSessionOptions options; |
| 3306 | JsepSessionDescription* offer(CreateRemoteOffer( |
| 3307 | options, cricket::SEC_DISABLED)); |
| 3308 | // Adds a DTLS fingerprint to the remote offer. |
| 3309 | cricket::SessionDescription* sdp = offer->description(); |
| 3310 | TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 3311 | ASSERT_TRUE(audio != NULL); |
| 3312 | ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); |
| 3313 | audio->description.identity_fingerprint.reset( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3314 | rtc::SSLFingerprint::CreateFromRfc4572( |
| 3315 | rtc::DIGEST_SHA_256, kFakeDtlsFingerprint)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3316 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3317 | offer); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3320 | // This test verifies DSCP is properly applied on the media channels. |
| 3321 | TEST_F(WebRtcSessionTest, TestDscpConstraint) { |
| 3322 | constraints_.reset(new FakeConstraints()); |
| 3323 | constraints_->AddOptional( |
| 3324 | webrtc::MediaConstraintsInterface::kEnableDscp, true); |
| 3325 | Init(NULL); |
| 3326 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3327 | SessionDescriptionInterface* offer = CreateOffer(); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 3328 | |
| 3329 | SetLocalDescriptionWithoutError(offer); |
| 3330 | |
| 3331 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3332 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 3333 | |
| 3334 | ASSERT_TRUE(video_channel_ != NULL); |
| 3335 | ASSERT_TRUE(voice_channel_ != NULL); |
| 3336 | cricket::AudioOptions audio_options; |
| 3337 | EXPECT_TRUE(voice_channel_->GetOptions(&audio_options)); |
| 3338 | cricket::VideoOptions video_options; |
| 3339 | EXPECT_TRUE(video_channel_->GetOptions(&video_options)); |
| 3340 | EXPECT_TRUE(audio_options.dscp.IsSet()); |
| 3341 | EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false)); |
| 3342 | EXPECT_TRUE(video_options.dscp.IsSet()); |
| 3343 | EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false)); |
| 3344 | } |
| 3345 | |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 3346 | TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) { |
| 3347 | constraints_.reset(new FakeConstraints()); |
| 3348 | constraints_->AddOptional( |
| 3349 | webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |
| 3350 | true); |
| 3351 | Init(NULL); |
| 3352 | mediastream_signaling_.SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3353 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 3354 | |
| 3355 | SetLocalDescriptionWithoutError(offer); |
| 3356 | |
| 3357 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3358 | |
| 3359 | ASSERT_TRUE(video_channel_ != NULL); |
| 3360 | cricket::VideoOptions video_options; |
| 3361 | EXPECT_TRUE(video_channel_->GetOptions(&video_options)); |
| 3362 | EXPECT_TRUE( |
| 3363 | video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false)); |
| 3364 | } |
| 3365 | |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 3366 | TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) { |
| 3367 | // Number of unsignalled receiving streams should be between 0 and |
| 3368 | // kMaxUnsignalledRecvStreams. |
| 3369 | SetAndVerifyNumUnsignalledRecvStreams(10, 10); |
| 3370 | SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1, |
| 3371 | kMaxUnsignalledRecvStreams); |
| 3372 | SetAndVerifyNumUnsignalledRecvStreams(-1, 0); |
| 3373 | } |
| 3374 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 3375 | TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { |
| 3376 | constraints_.reset(new FakeConstraints()); |
| 3377 | constraints_->AddOptional( |
| 3378 | webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe, |
| 3379 | true); |
| 3380 | Init(NULL); |
| 3381 | mediastream_signaling_.SendAudioVideoStream1(); |
| 3382 | SessionDescriptionInterface* offer = CreateOffer(); |
| 3383 | |
| 3384 | SetLocalDescriptionWithoutError(offer); |
| 3385 | |
| 3386 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 3387 | |
| 3388 | ASSERT_TRUE(voice_channel_ != NULL); |
| 3389 | cricket::AudioOptions audio_options; |
| 3390 | EXPECT_TRUE(voice_channel_->GetOptions(&audio_options)); |
| 3391 | EXPECT_TRUE( |
| 3392 | audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false)); |
| 3393 | } |
| 3394 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3395 | // Tests that we can renegotiate new media content with ICE candidates in the |
| 3396 | // new remote SDP. |
| 3397 | TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3398 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3399 | InitWithDtls(); |
| 3400 | SetFactoryDtlsSrtp(); |
| 3401 | |
| 3402 | mediastream_signaling_.UseOptionsAudioOnly(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3403 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3404 | SetLocalDescriptionWithoutError(offer); |
| 3405 | |
| 3406 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3407 | SetRemoteDescriptionWithoutError(answer); |
| 3408 | |
| 3409 | cricket::MediaSessionOptions options; |
| 3410 | options.has_video = true; |
| 3411 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 3412 | |
| 3413 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3414 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3415 | candidate1.set_component(1); |
| 3416 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 3417 | candidate1); |
| 3418 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 3419 | SetRemoteDescriptionWithoutError(offer); |
| 3420 | |
| 3421 | answer = CreateAnswer(NULL); |
| 3422 | SetLocalDescriptionWithoutError(answer); |
| 3423 | } |
| 3424 | |
| 3425 | // Tests that we can renegotiate new media content with ICE candidates separated |
| 3426 | // from the remote SDP. |
| 3427 | TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3428 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3429 | InitWithDtls(); |
| 3430 | SetFactoryDtlsSrtp(); |
| 3431 | |
| 3432 | mediastream_signaling_.UseOptionsAudioOnly(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3433 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3434 | SetLocalDescriptionWithoutError(offer); |
| 3435 | |
| 3436 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3437 | SetRemoteDescriptionWithoutError(answer); |
| 3438 | |
| 3439 | cricket::MediaSessionOptions options; |
| 3440 | options.has_video = true; |
| 3441 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 3442 | SetRemoteDescriptionWithoutError(offer); |
| 3443 | |
| 3444 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3445 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3446 | candidate1.set_component(1); |
| 3447 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 3448 | candidate1); |
| 3449 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate)); |
| 3450 | |
| 3451 | answer = CreateAnswer(NULL); |
| 3452 | SetLocalDescriptionWithoutError(answer); |
| 3453 | } |
| 3454 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3455 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 3456 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 3457 | // called more than once without returning to IceGatheringGathering. |