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