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" |
| 33 | #include "talk/app/webrtc/videotrack.h" |
| 34 | #include "talk/app/webrtc/test/fakeconstraints.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 35 | #include "talk/app/webrtc/test/fakedtlsidentityservice.h" |
| 36 | #include "talk/app/webrtc/test/fakemediastreamsignaling.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" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | #include "talk/base/fakenetwork.h" |
| 40 | #include "talk/base/firewallsocketserver.h" |
| 41 | #include "talk/base/gunit.h" |
| 42 | #include "talk/base/logging.h" |
| 43 | #include "talk/base/network.h" |
| 44 | #include "talk/base/physicalsocketserver.h" |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 45 | #include "talk/base/ssladapter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | #include "talk/base/sslstreamadapter.h" |
| 47 | #include "talk/base/stringutils.h" |
| 48 | #include "talk/base/thread.h" |
| 49 | #include "talk/base/virtualsocketserver.h" |
| 50 | #include "talk/media/base/fakemediaengine.h" |
| 51 | #include "talk/media/base/fakevideorenderer.h" |
| 52 | #include "talk/media/base/mediachannel.h" |
| 53 | #include "talk/media/devices/fakedevicemanager.h" |
| 54 | #include "talk/p2p/base/stunserver.h" |
| 55 | #include "talk/p2p/base/teststunserver.h" |
| 56 | #include "talk/p2p/client/basicportallocator.h" |
| 57 | #include "talk/session/media/channelmanager.h" |
| 58 | #include "talk/session/media/mediasession.h" |
| 59 | |
| 60 | #define MAYBE_SKIP_TEST(feature) \ |
| 61 | if (!(feature())) { \ |
| 62 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 63 | return; \ |
| 64 | } |
| 65 | |
| 66 | using cricket::BaseSession; |
| 67 | using cricket::DF_PLAY; |
| 68 | using cricket::DF_SEND; |
| 69 | using cricket::FakeVoiceMediaChannel; |
| 70 | using cricket::NS_GINGLE_P2P; |
| 71 | using cricket::NS_JINGLE_ICE_UDP; |
| 72 | using cricket::TransportInfo; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | using talk_base::SocketAddress; |
| 74 | using talk_base::scoped_ptr; |
| 75 | using webrtc::CreateSessionDescription; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 76 | using webrtc::CreateSessionDescriptionObserver; |
| 77 | using webrtc::CreateSessionDescriptionRequest; |
| 78 | using webrtc::DTLSIdentityRequestObserver; |
| 79 | using webrtc::DTLSIdentityServiceInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | using webrtc::FakeConstraints; |
| 81 | using webrtc::IceCandidateCollection; |
| 82 | using webrtc::JsepIceCandidate; |
| 83 | using webrtc::JsepSessionDescription; |
| 84 | using webrtc::PeerConnectionInterface; |
| 85 | using webrtc::SessionDescriptionInterface; |
| 86 | using webrtc::StreamCollection; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 87 | using webrtc::WebRtcSession; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | using webrtc::kMlineMismatch; |
| 89 | using webrtc::kSdpWithoutCrypto; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 90 | using webrtc::kSdpWithoutSdesAndDtlsDisabled; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 91 | using webrtc::kSdpWithoutIceUfragPwd; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | using webrtc::kSessionError; |
| 93 | using webrtc::kSetLocalSdpFailed; |
| 94 | using webrtc::kSetRemoteSdpFailed; |
| 95 | using webrtc::kPushDownAnswerTDFailed; |
| 96 | using webrtc::kPushDownPranswerTDFailed; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 97 | using webrtc::kBundleWithoutRtcpMux; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | |
| 99 | static const SocketAddress kClientAddr1("11.11.11.11", 0); |
| 100 | static const SocketAddress kClientAddr2("22.22.22.22", 0); |
| 101 | static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 102 | |
| 103 | static const char kSessionVersion[] = "1"; |
| 104 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | // Media index of candidates belonging to the first media content. |
| 106 | static const int kMediaContentIndex0 = 0; |
| 107 | static const char kMediaContentName0[] = "audio"; |
| 108 | |
| 109 | // Media index of candidates belonging to the second media content. |
| 110 | static const int kMediaContentIndex1 = 1; |
| 111 | static const char kMediaContentName1[] = "video"; |
| 112 | |
| 113 | static const int kIceCandidatesTimeout = 10000; |
| 114 | |
| 115 | static const cricket::AudioCodec |
| 116 | kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0); |
| 117 | static const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0); |
| 118 | static const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0); |
| 119 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 120 | static const char kFakeDtlsFingerprint[] = |
| 121 | "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:" |
| 122 | "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24"; |
| 123 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | // Add some extra |newlines| to the |message| after |line|. |
| 125 | static void InjectAfter(const std::string& line, |
| 126 | const std::string& newlines, |
| 127 | std::string* message) { |
| 128 | const std::string tmp = line + newlines; |
| 129 | talk_base::replace_substrs(line.c_str(), line.length(), |
| 130 | tmp.c_str(), tmp.length(), message); |
| 131 | } |
| 132 | |
| 133 | class MockIceObserver : public webrtc::IceObserver { |
| 134 | public: |
| 135 | MockIceObserver() |
| 136 | : oncandidatesready_(false), |
| 137 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 138 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 139 | } |
| 140 | |
| 141 | virtual void OnIceConnectionChange( |
| 142 | PeerConnectionInterface::IceConnectionState new_state) { |
| 143 | ice_connection_state_ = new_state; |
| 144 | } |
| 145 | virtual void OnIceGatheringChange( |
| 146 | PeerConnectionInterface::IceGatheringState new_state) { |
| 147 | // We can never transition back to "new". |
| 148 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 149 | ice_gathering_state_ = new_state; |
| 150 | |
| 151 | // oncandidatesready_ really means "ICE gathering is complete". |
| 152 | // This if statement ensures that this value remains correct when we |
| 153 | // transition from kIceGatheringComplete to kIceGatheringGathering. |
| 154 | if (new_state == PeerConnectionInterface::kIceGatheringGathering) { |
| 155 | oncandidatesready_ = false; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // Found a new candidate. |
| 160 | virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) { |
| 161 | if (candidate->sdp_mline_index() == kMediaContentIndex0) { |
| 162 | mline_0_candidates_.push_back(candidate->candidate()); |
| 163 | } else if (candidate->sdp_mline_index() == kMediaContentIndex1) { |
| 164 | mline_1_candidates_.push_back(candidate->candidate()); |
| 165 | } |
| 166 | // The ICE gathering state should always be Gathering when a candidate is |
| 167 | // received (or possibly Completed in the case of the final candidate). |
| 168 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 169 | } |
| 170 | |
| 171 | // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange. |
| 172 | virtual void OnIceComplete() { |
| 173 | EXPECT_FALSE(oncandidatesready_); |
| 174 | oncandidatesready_ = true; |
| 175 | |
| 176 | // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should |
| 177 | // be called approximately simultaneously. For ease of testing, this |
| 178 | // check additionally requires that they be called in the above order. |
| 179 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, |
| 180 | ice_gathering_state_); |
| 181 | } |
| 182 | |
| 183 | bool oncandidatesready_; |
| 184 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 185 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 186 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 187 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
| 188 | }; |
| 189 | |
| 190 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 191 | public: |
| 192 | WebRtcSessionForTest(cricket::ChannelManager* cmgr, |
| 193 | talk_base::Thread* signaling_thread, |
| 194 | talk_base::Thread* worker_thread, |
| 195 | cricket::PortAllocator* port_allocator, |
| 196 | webrtc::IceObserver* ice_observer, |
| 197 | webrtc::MediaStreamSignaling* mediastream_signaling) |
| 198 | : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator, |
| 199 | mediastream_signaling) { |
| 200 | RegisterIceObserver(ice_observer); |
| 201 | } |
| 202 | virtual ~WebRtcSessionForTest() {} |
| 203 | |
| 204 | using cricket::BaseSession::GetTransportProxy; |
| 205 | using webrtc::WebRtcSession::SetAudioPlayout; |
| 206 | using webrtc::WebRtcSession::SetAudioSend; |
| 207 | using webrtc::WebRtcSession::SetCaptureDevice; |
| 208 | using webrtc::WebRtcSession::SetVideoPlayout; |
| 209 | using webrtc::WebRtcSession::SetVideoSend; |
| 210 | }; |
| 211 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 212 | class WebRtcSessionCreateSDPObserverForTest |
| 213 | : public talk_base::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 215 | enum State { |
| 216 | kInit, |
| 217 | kFailed, |
| 218 | kSucceeded, |
| 219 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 220 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 221 | |
| 222 | // CreateSessionDescriptionObserver implementation. |
| 223 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 224 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 225 | state_ = kSucceeded; |
| 226 | } |
| 227 | virtual void OnFailure(const std::string& error) { |
| 228 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | } |
| 230 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 231 | SessionDescriptionInterface* description() { return description_.get(); } |
| 232 | |
| 233 | SessionDescriptionInterface* ReleaseDescription() { |
| 234 | return description_.release(); |
| 235 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 237 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 239 | protected: |
| 240 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 241 | |
| 242 | private: |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 243 | talk_base::scoped_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 244 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 247 | class FakeAudioRenderer : public cricket::AudioRenderer { |
| 248 | public: |
| 249 | FakeAudioRenderer() : channel_id_(-1) {} |
| 250 | |
| 251 | virtual void AddChannel(int channel_id) OVERRIDE { |
| 252 | ASSERT(channel_id_ == -1); |
| 253 | channel_id_ = channel_id; |
| 254 | } |
| 255 | virtual void RemoveChannel(int channel_id) OVERRIDE { |
| 256 | ASSERT(channel_id == channel_id_); |
| 257 | channel_id_ = -1; |
| 258 | } |
| 259 | |
| 260 | int channel_id() const { return channel_id_; } |
| 261 | private: |
| 262 | int channel_id_; |
| 263 | }; |
| 264 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 265 | class WebRtcSessionTest : public testing::Test { |
| 266 | protected: |
| 267 | // TODO Investigate why ChannelManager crashes, if it's created |
| 268 | // after stun_server. |
| 269 | WebRtcSessionTest() |
| 270 | : media_engine_(new cricket::FakeMediaEngine()), |
| 271 | data_engine_(new cricket::FakeDataEngine()), |
| 272 | device_manager_(new cricket::FakeDeviceManager()), |
| 273 | channel_manager_(new cricket::ChannelManager( |
| 274 | media_engine_, data_engine_, device_manager_, |
| 275 | new cricket::CaptureManager(), talk_base::Thread::Current())), |
| 276 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 277 | desc_factory_(new cricket::MediaSessionDescriptionFactory( |
| 278 | channel_manager_.get(), tdesc_factory_.get())), |
| 279 | pss_(new talk_base::PhysicalSocketServer), |
| 280 | vss_(new talk_base::VirtualSocketServer(pss_.get())), |
| 281 | fss_(new talk_base::FirewallSocketServer(vss_.get())), |
| 282 | ss_scope_(fss_.get()), |
| 283 | stun_server_(talk_base::Thread::Current(), kStunAddr), |
| 284 | allocator_(&network_manager_, kStunAddr, |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 285 | SocketAddress(), SocketAddress(), SocketAddress()), |
| 286 | mediastream_signaling_(channel_manager_.get()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID); |
| 288 | allocator_.set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 289 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 290 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 291 | EXPECT_TRUE(channel_manager_->Init()); |
| 292 | desc_factory_->set_add_legacy_streams(false); |
| 293 | } |
| 294 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 295 | static void SetUpTestCase() { |
| 296 | talk_base::InitializeSSL(); |
| 297 | } |
| 298 | |
| 299 | static void TearDownTestCase() { |
| 300 | talk_base::CleanupSSL(); |
| 301 | } |
| 302 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 303 | void AddInterface(const SocketAddress& addr) { |
| 304 | network_manager_.AddInterface(addr); |
| 305 | } |
| 306 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 307 | void Init(DTLSIdentityServiceInterface* identity_service) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | ASSERT_TRUE(session_.get() == NULL); |
| 309 | session_.reset(new WebRtcSessionForTest( |
| 310 | channel_manager_.get(), talk_base::Thread::Current(), |
| 311 | talk_base::Thread::Current(), &allocator_, |
| 312 | &observer_, |
| 313 | &mediastream_signaling_)); |
| 314 | |
| 315 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 316 | observer_.ice_connection_state_); |
| 317 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 318 | observer_.ice_gathering_state_); |
| 319 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 320 | EXPECT_TRUE(session_->Initialize(constraints_.get(), identity_service)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void InitWithDtmfCodec() { |
| 324 | // Add kTelephoneEventCodec for dtmf test. |
| 325 | std::vector<cricket::AudioCodec> codecs; |
| 326 | codecs.push_back(kTelephoneEventCodec); |
| 327 | media_engine_->SetAudioCodecs(codecs); |
| 328 | desc_factory_->set_audio_codecs(codecs); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 329 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | } |
| 331 | |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 332 | void InitWithDtls(bool identity_request_should_fail = false) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 333 | FakeIdentityService* identity_service = new FakeIdentityService(); |
| 334 | identity_service->set_should_fail(identity_request_should_fail); |
| 335 | Init(identity_service); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | // Creates a local offer and applies it. Starts ice. |
| 339 | // Call mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 340 | // to decide which streams to create. |
| 341 | void InitiateCall() { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 342 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | SetLocalDescriptionWithoutError(offer); |
| 344 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 345 | observer_.ice_gathering_state_, |
| 346 | kIceCandidatesTimeout); |
| 347 | } |
| 348 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 349 | SessionDescriptionInterface* CreateOffer( |
| 350 | const webrtc::MediaConstraintsInterface* constraints) { |
| 351 | talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
| 352 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
| 353 | session_->CreateOffer(observer, constraints); |
| 354 | EXPECT_TRUE_WAIT( |
| 355 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 356 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 357 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | SessionDescriptionInterface* CreateAnswer( |
| 361 | const webrtc::MediaConstraintsInterface* constraints) { |
| 362 | talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
| 363 | = new WebRtcSessionCreateSDPObserverForTest(); |
| 364 | session_->CreateAnswer(observer, constraints); |
| 365 | EXPECT_TRUE_WAIT( |
| 366 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 367 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 368 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 369 | } |
| 370 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 371 | bool ChannelsExist() { |
| 372 | return (session_->voice_channel() != NULL && |
| 373 | session_->video_channel() != NULL); |
| 374 | } |
| 375 | |
| 376 | void CheckTransportChannels() { |
| 377 | EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL); |
| 378 | EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL); |
| 379 | EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL); |
| 380 | EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL); |
| 381 | } |
| 382 | |
| 383 | void VerifyCryptoParams(const cricket::SessionDescription* sdp) { |
| 384 | ASSERT_TRUE(session_.get() != NULL); |
| 385 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 386 | ASSERT_TRUE(content != NULL); |
| 387 | const cricket::AudioContentDescription* audio_content = |
| 388 | static_cast<const cricket::AudioContentDescription*>( |
| 389 | content->description); |
| 390 | ASSERT_TRUE(audio_content != NULL); |
| 391 | ASSERT_EQ(1U, audio_content->cryptos().size()); |
| 392 | ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); |
| 393 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 394 | audio_content->cryptos()[0].cipher_suite); |
| 395 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 396 | audio_content->protocol()); |
| 397 | |
| 398 | content = cricket::GetFirstVideoContent(sdp); |
| 399 | ASSERT_TRUE(content != NULL); |
| 400 | const cricket::VideoContentDescription* video_content = |
| 401 | static_cast<const cricket::VideoContentDescription*>( |
| 402 | content->description); |
| 403 | ASSERT_TRUE(video_content != NULL); |
| 404 | ASSERT_EQ(1U, video_content->cryptos().size()); |
| 405 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 406 | video_content->cryptos()[0].cipher_suite); |
| 407 | ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); |
| 408 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 409 | video_content->protocol()); |
| 410 | } |
| 411 | |
| 412 | void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { |
| 413 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 414 | ASSERT_TRUE(content != NULL); |
| 415 | const cricket::AudioContentDescription* audio_content = |
| 416 | static_cast<const cricket::AudioContentDescription*>( |
| 417 | content->description); |
| 418 | ASSERT_TRUE(audio_content != NULL); |
| 419 | ASSERT_EQ(0U, audio_content->cryptos().size()); |
| 420 | |
| 421 | content = cricket::GetFirstVideoContent(sdp); |
| 422 | ASSERT_TRUE(content != NULL); |
| 423 | const cricket::VideoContentDescription* video_content = |
| 424 | static_cast<const cricket::VideoContentDescription*>( |
| 425 | content->description); |
| 426 | ASSERT_TRUE(video_content != NULL); |
| 427 | ASSERT_EQ(0U, video_content->cryptos().size()); |
| 428 | |
| 429 | if (dtls) { |
| 430 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 431 | audio_content->protocol()); |
| 432 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 433 | video_content->protocol()); |
| 434 | } else { |
| 435 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 436 | audio_content->protocol()); |
| 437 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 438 | video_content->protocol()); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // Set the internal fake description factories to do DTLS-SRTP. |
| 443 | void SetFactoryDtlsSrtp() { |
| 444 | desc_factory_->set_secure(cricket::SEC_ENABLED); |
| 445 | std::string identity_name = "WebRTC" + |
| 446 | talk_base::ToString(talk_base::CreateRandomId()); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 447 | identity_.reset(talk_base::SSLIdentity::Generate(identity_name)); |
| 448 | tdesc_factory_->set_identity(identity_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 449 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 450 | } |
| 451 | |
| 452 | void VerifyFingerprintStatus(const cricket::SessionDescription* sdp, |
| 453 | bool expected) { |
| 454 | const TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 455 | ASSERT_TRUE(audio != NULL); |
| 456 | ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | const TransportInfo* video = sdp->GetTransportInfoByName("video"); |
| 458 | ASSERT_TRUE(video != NULL); |
| 459 | ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void VerifyAnswerFromNonCryptoOffer() { |
| 463 | // Create a SDP without Crypto. |
| 464 | cricket::MediaSessionOptions options; |
| 465 | options.has_video = true; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 466 | JsepSessionDescription* offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 467 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 468 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | VerifyNoCryptoParams(offer->description(), false); |
| 470 | SetRemoteDescriptionExpectError("Called with a SDP without crypto enabled", |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 471 | offer); |
| 472 | const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 473 | // Answer should be NULL as no crypto params in offer. |
| 474 | ASSERT_TRUE(answer == NULL); |
| 475 | } |
| 476 | |
| 477 | void VerifyAnswerFromCryptoOffer() { |
| 478 | cricket::MediaSessionOptions options; |
| 479 | options.has_video = true; |
| 480 | options.bundle_enabled = true; |
| 481 | scoped_ptr<JsepSessionDescription> offer( |
| 482 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 483 | ASSERT_TRUE(offer.get() != NULL); |
| 484 | VerifyCryptoParams(offer->description()); |
| 485 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 486 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | ASSERT_TRUE(answer.get() != NULL); |
| 488 | VerifyCryptoParams(answer->description()); |
| 489 | } |
| 490 | |
| 491 | void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1, |
| 492 | const cricket::SessionDescription* desc2, |
| 493 | bool expect_equal) { |
| 494 | if (desc1->contents().size() != desc2->contents().size()) { |
| 495 | EXPECT_FALSE(expect_equal); |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | const cricket::ContentInfos& contents = desc1->contents(); |
| 500 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 501 | |
| 502 | for (; it != contents.end(); ++it) { |
| 503 | const cricket::TransportDescription* transport_desc1 = |
| 504 | desc1->GetTransportDescriptionByName(it->name); |
| 505 | const cricket::TransportDescription* transport_desc2 = |
| 506 | desc2->GetTransportDescriptionByName(it->name); |
| 507 | if (!transport_desc1 || !transport_desc2) { |
| 508 | EXPECT_FALSE(expect_equal); |
| 509 | return; |
| 510 | } |
| 511 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 512 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 513 | EXPECT_FALSE(expect_equal); |
| 514 | return; |
| 515 | } |
| 516 | } |
| 517 | EXPECT_TRUE(expect_equal); |
| 518 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 519 | |
| 520 | void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 521 | std::string *sdp) { |
| 522 | const cricket::SessionDescription* desc = current_desc->description(); |
| 523 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 524 | |
| 525 | const cricket::ContentInfos& contents = desc->contents(); |
| 526 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 527 | // Replace ufrag and pwd lines with empty strings. |
| 528 | for (; it != contents.end(); ++it) { |
| 529 | const cricket::TransportDescription* transport_desc = |
| 530 | desc->GetTransportDescriptionByName(it->name); |
| 531 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 532 | + "\r\n"; |
| 533 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 534 | + "\r\n"; |
| 535 | talk_base::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
| 536 | "", 0, |
| 537 | sdp); |
| 538 | talk_base::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
| 539 | "", 0, |
| 540 | sdp); |
| 541 | } |
| 542 | } |
| 543 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 544 | // Creates a remote offer and and applies it as a remote description, |
| 545 | // creates a local answer and applies is as a local description. |
| 546 | // Call mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 547 | // to decide which local and remote streams to create. |
| 548 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 549 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 550 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 551 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 552 | SetLocalDescriptionWithoutError(answer); |
| 553 | } |
| 554 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 555 | EXPECT_TRUE(session_->SetLocalDescription(desc, NULL)); |
| 556 | } |
| 557 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
| 558 | BaseSession::State expected_state) { |
| 559 | SetLocalDescriptionWithoutError(desc); |
| 560 | EXPECT_EQ(expected_state, session_->state()); |
| 561 | } |
| 562 | void SetLocalDescriptionExpectError(const std::string& expected_error, |
| 563 | SessionDescriptionInterface* desc) { |
| 564 | std::string error; |
| 565 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
| 566 | EXPECT_NE(std::string::npos, error.find(kSetLocalSdpFailed)); |
| 567 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 568 | } |
| 569 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 570 | EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL)); |
| 571 | } |
| 572 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
| 573 | BaseSession::State expected_state) { |
| 574 | SetRemoteDescriptionWithoutError(desc); |
| 575 | EXPECT_EQ(expected_state, session_->state()); |
| 576 | } |
| 577 | void SetRemoteDescriptionExpectError(const std::string& expected_error, |
| 578 | SessionDescriptionInterface* desc) { |
| 579 | std::string error; |
| 580 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
| 581 | EXPECT_NE(std::string::npos, error.find(kSetRemoteSdpFailed)); |
| 582 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 583 | } |
| 584 | |
| 585 | void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer, |
| 586 | SessionDescriptionInterface** nocrypto_answer) { |
| 587 | // Create a SDP without Crypto. |
| 588 | cricket::MediaSessionOptions options; |
| 589 | options.has_video = true; |
| 590 | options.bundle_enabled = true; |
| 591 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 592 | ASSERT_TRUE(*offer != NULL); |
| 593 | VerifyCryptoParams((*offer)->description()); |
| 594 | |
| 595 | *nocrypto_answer = CreateRemoteAnswer(*offer, options, |
| 596 | cricket::SEC_DISABLED); |
| 597 | EXPECT_TRUE(*nocrypto_answer != NULL); |
| 598 | } |
| 599 | |
| 600 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 601 | cricket::MediaSessionOptions options, |
| 602 | cricket::SecurePolicy secure_policy, |
| 603 | const std::string& session_version, |
| 604 | const SessionDescriptionInterface* current_desc) { |
| 605 | std::string session_id = talk_base::ToString(talk_base::CreateRandomId64()); |
| 606 | const cricket::SessionDescription* cricket_desc = NULL; |
| 607 | if (current_desc) { |
| 608 | cricket_desc = current_desc->description(); |
| 609 | session_id = current_desc->session_id(); |
| 610 | } |
| 611 | |
| 612 | desc_factory_->set_secure(secure_policy); |
| 613 | JsepSessionDescription* offer( |
| 614 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 615 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 616 | session_id, session_version)) { |
| 617 | delete offer; |
| 618 | offer = NULL; |
| 619 | } |
| 620 | return offer; |
| 621 | } |
| 622 | JsepSessionDescription* CreateRemoteOffer( |
| 623 | cricket::MediaSessionOptions options) { |
| 624 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 625 | kSessionVersion, NULL); |
| 626 | } |
| 627 | JsepSessionDescription* CreateRemoteOffer( |
| 628 | cricket::MediaSessionOptions options, cricket::SecurePolicy policy) { |
| 629 | return CreateRemoteOfferWithVersion(options, policy, kSessionVersion, NULL); |
| 630 | } |
| 631 | JsepSessionDescription* CreateRemoteOffer( |
| 632 | cricket::MediaSessionOptions options, |
| 633 | const SessionDescriptionInterface* current_desc) { |
| 634 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 635 | kSessionVersion, current_desc); |
| 636 | } |
| 637 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 638 | JsepSessionDescription* CreateRemoteOfferWithSctpPort( |
| 639 | const char* sctp_stream_name, int new_port, |
| 640 | cricket::MediaSessionOptions options) { |
| 641 | options.data_channel_type = cricket::DCT_SCTP; |
| 642 | options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel", |
| 643 | sctp_stream_name); |
| 644 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 645 | } |
| 646 | |
| 647 | // Takes ownership of offer_basis (and deletes it). |
| 648 | JsepSessionDescription* ChangeSDPSctpPort( |
| 649 | int new_port, webrtc::SessionDescriptionInterface *offer_basis) { |
| 650 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 651 | // SessionDescription from the mutated string. |
| 652 | const char* default_port_str = "5000"; |
| 653 | char new_port_str[16]; |
| 654 | talk_base::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port); |
| 655 | std::string offer_str; |
| 656 | offer_basis->ToString(&offer_str); |
| 657 | talk_base::replace_substrs(default_port_str, strlen(default_port_str), |
| 658 | new_port_str, strlen(new_port_str), |
| 659 | &offer_str); |
| 660 | JsepSessionDescription* offer = new JsepSessionDescription( |
| 661 | offer_basis->type()); |
| 662 | delete offer_basis; |
| 663 | offer->Initialize(offer_str, NULL); |
| 664 | return offer; |
| 665 | } |
| 666 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX() |
| 668 | // before this function to decide which streams to create. |
| 669 | JsepSessionDescription* CreateRemoteOffer() { |
| 670 | cricket::MediaSessionOptions options; |
| 671 | mediastream_signaling_.GetOptionsForAnswer(NULL, &options); |
| 672 | return CreateRemoteOffer(options, session_->remote_description()); |
| 673 | } |
| 674 | |
| 675 | JsepSessionDescription* CreateRemoteAnswer( |
| 676 | const SessionDescriptionInterface* offer, |
| 677 | cricket::MediaSessionOptions options, |
| 678 | cricket::SecurePolicy policy) { |
| 679 | desc_factory_->set_secure(policy); |
| 680 | const std::string session_id = |
| 681 | talk_base::ToString(talk_base::CreateRandomId64()); |
| 682 | JsepSessionDescription* answer( |
| 683 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 684 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 685 | options, NULL), |
| 686 | session_id, kSessionVersion)) { |
| 687 | delete answer; |
| 688 | answer = NULL; |
| 689 | } |
| 690 | return answer; |
| 691 | } |
| 692 | |
| 693 | JsepSessionDescription* CreateRemoteAnswer( |
| 694 | const SessionDescriptionInterface* offer, |
| 695 | cricket::MediaSessionOptions options) { |
| 696 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 697 | } |
| 698 | |
| 699 | // Creates an answer session description with streams based on |
| 700 | // |mediastream_signaling_|. Call |
| 701 | // mediastream_signaling_.UseOptionsWithStreamX() before this function |
| 702 | // to decide which streams to create. |
| 703 | JsepSessionDescription* CreateRemoteAnswer( |
| 704 | const SessionDescriptionInterface* offer) { |
| 705 | cricket::MediaSessionOptions options; |
| 706 | mediastream_signaling_.GetOptionsForAnswer(NULL, &options); |
| 707 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 708 | } |
| 709 | |
| 710 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
| 711 | AddInterface(kClientAddr1); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 712 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 713 | mediastream_signaling_.SendAudioVideoStream1(); |
| 714 | FakeConstraints constraints; |
| 715 | constraints.SetMandatoryUseRtpMux(bundle); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 716 | SessionDescriptionInterface* offer = CreateOffer(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 717 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 718 | // and answer. |
| 719 | SetLocalDescriptionWithoutError(offer); |
| 720 | |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 721 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 722 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 723 | std::string sdp; |
| 724 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 725 | |
| 726 | size_t expected_candidate_num = 2; |
| 727 | if (!rtcp_mux) { |
| 728 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 729 | // for rtp and rtcp. |
| 730 | expected_candidate_num = 4; |
| 731 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 732 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 733 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
| 734 | talk_base::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
| 735 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 736 | &sdp); |
| 737 | } |
| 738 | |
| 739 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 740 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 741 | |
| 742 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 743 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 744 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 745 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
| 746 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
| 747 | for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) { |
| 748 | cricket::Candidate c0 = observer_.mline_0_candidates_[i]; |
| 749 | cricket::Candidate c1 = observer_.mline_1_candidates_[i]; |
| 750 | if (bundle) { |
| 751 | EXPECT_TRUE(c0.IsEquivalent(c1)); |
| 752 | } else { |
| 753 | EXPECT_FALSE(c0.IsEquivalent(c1)); |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | // Tests that we can only send DTMF when the dtmf codec is supported. |
| 758 | void TestCanInsertDtmf(bool can) { |
| 759 | if (can) { |
| 760 | InitWithDtmfCodec(); |
| 761 | } else { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 762 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | } |
| 764 | mediastream_signaling_.SendAudioVideoStream1(); |
| 765 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 766 | EXPECT_FALSE(session_->CanInsertDtmf("")); |
| 767 | EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1)); |
| 768 | } |
| 769 | |
| 770 | // The method sets up a call from the session to itself, in a loopback |
| 771 | // arrangement. It also uses a firewall rule to create a temporary |
| 772 | // disconnection. This code is placed as a method so that it can be invoked |
| 773 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 774 | // While running the call, this method also checks if the session goes through |
| 775 | // the correct sequence of ICE states when a connection is established, |
| 776 | // broken, and re-established. |
| 777 | // The Connection state should go: |
| 778 | // New -> Checking -> Connected -> Disconnected -> Connected. |
| 779 | // The Gathering state should go: New -> Gathering -> Completed. |
| 780 | void TestLoopbackCall() { |
| 781 | AddInterface(kClientAddr1); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 782 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 783 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 784 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | |
| 786 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 787 | observer_.ice_gathering_state_); |
| 788 | SetLocalDescriptionWithoutError(offer); |
| 789 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 790 | observer_.ice_connection_state_); |
| 791 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
| 792 | observer_.ice_gathering_state_, |
| 793 | kIceCandidatesTimeout); |
| 794 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 795 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 796 | observer_.ice_gathering_state_, |
| 797 | kIceCandidatesTimeout); |
| 798 | |
| 799 | std::string sdp; |
| 800 | offer->ToString(&sdp); |
| 801 | SessionDescriptionInterface* desc = |
| 802 | webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp); |
| 803 | ASSERT_TRUE(desc != NULL); |
| 804 | SetRemoteDescriptionWithoutError(desc); |
| 805 | |
| 806 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
| 807 | observer_.ice_connection_state_, |
| 808 | kIceCandidatesTimeout); |
| 809 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected, |
| 810 | observer_.ice_connection_state_, |
| 811 | kIceCandidatesTimeout); |
| 812 | // TODO(bemasc): EXPECT(Completed) once the details are standardized. |
| 813 | |
| 814 | // Adding firewall rule to block ping requests, which should cause |
| 815 | // transport channel failure. |
| 816 | fss_->AddRule(false, talk_base::FP_ANY, talk_base::FD_ANY, kClientAddr1); |
| 817 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 818 | observer_.ice_connection_state_, |
| 819 | kIceCandidatesTimeout); |
| 820 | |
| 821 | // Clearing the rules, session should move back to completed state. |
| 822 | fss_->ClearRules(); |
| 823 | // Session is automatically calling OnSignalingReady after creation of |
| 824 | // new portallocator session which will allocate new set of candidates. |
| 825 | |
| 826 | // TODO(bemasc): Change this to Completed once the details are standardized. |
| 827 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionConnected, |
| 828 | observer_.ice_connection_state_, |
| 829 | kIceCandidatesTimeout); |
| 830 | } |
| 831 | |
| 832 | void VerifyTransportType(const std::string& content_name, |
| 833 | cricket::TransportProtocol protocol) { |
| 834 | const cricket::Transport* transport = session_->GetTransport(content_name); |
| 835 | ASSERT_TRUE(transport != NULL); |
| 836 | EXPECT_EQ(protocol, transport->protocol()); |
| 837 | } |
| 838 | |
| 839 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 840 | void AddCNCodecs() { |
| 841 | // Add kTelephoneEventCodec for dtmf test. |
| 842 | std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();; |
| 843 | codecs.push_back(kCNCodec1); |
| 844 | codecs.push_back(kCNCodec2); |
| 845 | media_engine_->SetAudioCodecs(codecs); |
| 846 | desc_factory_->set_audio_codecs(codecs); |
| 847 | } |
| 848 | |
| 849 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 850 | const cricket::ContentDescription* description = content->description; |
| 851 | ASSERT(description != NULL); |
| 852 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 853 | static_cast<const cricket::AudioContentDescription*>(description); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 854 | ASSERT(audio_content_desc != NULL); |
| 855 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 856 | if (audio_content_desc->codecs()[i].name == "CN") |
| 857 | return false; |
| 858 | } |
| 859 | return true; |
| 860 | } |
| 861 | |
| 862 | void SetLocalDescriptionWithDataChannel() { |
| 863 | webrtc::DataChannelInit dci; |
| 864 | dci.reliable = false; |
| 865 | session_->CreateDataChannel("datachannel", &dci); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 866 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 867 | SetLocalDescriptionWithoutError(offer); |
| 868 | } |
| 869 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 870 | void VerifyMultipleAsyncCreateDescription( |
| 871 | bool success, CreateSessionDescriptionRequest::Type type) { |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 872 | InitWithDtls(!success); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 873 | |
| 874 | if (type == CreateSessionDescriptionRequest::kAnswer) { |
| 875 | cricket::MediaSessionOptions options; |
| 876 | scoped_ptr<JsepSessionDescription> offer( |
| 877 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 878 | ASSERT_TRUE(offer.get() != NULL); |
| 879 | SetRemoteDescriptionWithoutError(offer.release()); |
| 880 | } |
| 881 | |
| 882 | const int kNumber = 3; |
| 883 | talk_base::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
| 884 | observers[kNumber]; |
| 885 | for (int i = 0; i < kNumber; ++i) { |
| 886 | observers[i] = new WebRtcSessionCreateSDPObserverForTest(); |
| 887 | if (type == CreateSessionDescriptionRequest::kOffer) { |
| 888 | session_->CreateOffer(observers[i], NULL); |
| 889 | } else { |
| 890 | session_->CreateAnswer(observers[i], NULL); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | WebRtcSessionCreateSDPObserverForTest::State expected_state = |
| 895 | success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded : |
| 896 | WebRtcSessionCreateSDPObserverForTest::kFailed; |
| 897 | |
| 898 | for (int i = 0; i < kNumber; ++i) { |
| 899 | EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000); |
| 900 | if (success) { |
| 901 | EXPECT_TRUE(observers[i]->description() != NULL); |
| 902 | } else { |
| 903 | EXPECT_TRUE(observers[i]->description() == NULL); |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 908 | cricket::FakeMediaEngine* media_engine_; |
| 909 | cricket::FakeDataEngine* data_engine_; |
| 910 | cricket::FakeDeviceManager* device_manager_; |
| 911 | talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_; |
| 912 | talk_base::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 913 | talk_base::scoped_ptr<talk_base::SSLIdentity> identity_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 914 | talk_base::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
| 915 | talk_base::scoped_ptr<talk_base::PhysicalSocketServer> pss_; |
| 916 | talk_base::scoped_ptr<talk_base::VirtualSocketServer> vss_; |
| 917 | talk_base::scoped_ptr<talk_base::FirewallSocketServer> fss_; |
| 918 | talk_base::SocketServerScope ss_scope_; |
| 919 | cricket::TestStunServer stun_server_; |
| 920 | talk_base::FakeNetworkManager network_manager_; |
| 921 | cricket::BasicPortAllocator allocator_; |
| 922 | talk_base::scoped_ptr<FakeConstraints> constraints_; |
| 923 | FakeMediaStreamSignaling mediastream_signaling_; |
| 924 | talk_base::scoped_ptr<WebRtcSessionForTest> session_; |
| 925 | MockIceObserver observer_; |
| 926 | cricket::FakeVideoMediaChannel* video_channel_; |
| 927 | cricket::FakeVoiceMediaChannel* voice_channel_; |
| 928 | }; |
| 929 | |
| 930 | TEST_F(WebRtcSessionTest, TestInitialize) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 931 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | TEST_F(WebRtcSessionTest, TestInitializeWithDtls) { |
| 935 | InitWithDtls(); |
| 936 | } |
| 937 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 938 | // Verifies that WebRtcSession uses SEC_REQUIRED by default. |
| 939 | TEST_F(WebRtcSessionTest, TestDefaultSetSecurePolicy) { |
| 940 | Init(NULL); |
| 941 | EXPECT_EQ(cricket::SEC_REQUIRED, session_->secure_policy()); |
| 942 | } |
| 943 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 944 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 945 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 946 | } |
| 947 | |
| 948 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 949 | // with rtcp-mux and/or bundle. |
| 950 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 951 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 952 | } |
| 953 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 954 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 955 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 956 | } |
| 957 | |
| 958 | TEST_F(WebRtcSessionTest, TestMultihomeCandidates) { |
| 959 | AddInterface(kClientAddr1); |
| 960 | AddInterface(kClientAddr2); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 961 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 962 | mediastream_signaling_.SendAudioVideoStream1(); |
| 963 | InitiateCall(); |
| 964 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 965 | EXPECT_EQ(8u, observer_.mline_0_candidates_.size()); |
| 966 | EXPECT_EQ(8u, observer_.mline_1_candidates_.size()); |
| 967 | } |
| 968 | |
| 969 | TEST_F(WebRtcSessionTest, TestStunError) { |
| 970 | AddInterface(kClientAddr1); |
| 971 | AddInterface(kClientAddr2); |
| 972 | fss_->AddRule(false, talk_base::FP_UDP, talk_base::FD_ANY, kClientAddr1); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 973 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 974 | mediastream_signaling_.SendAudioVideoStream1(); |
| 975 | InitiateCall(); |
| 976 | // Since kClientAddr1 is blocked, not expecting stun candidates for it. |
| 977 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 978 | EXPECT_EQ(6u, observer_.mline_0_candidates_.size()); |
| 979 | EXPECT_EQ(6u, observer_.mline_1_candidates_.size()); |
| 980 | } |
| 981 | |
| 982 | // Test creating offers and receive answers and make sure the |
| 983 | // media engine creates the expected send and receive streams. |
| 984 | TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 985 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 986 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 987 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 988 | const std::string session_id_orig = offer->session_id(); |
| 989 | const std::string session_version_orig = offer->session_version(); |
| 990 | SetLocalDescriptionWithoutError(offer); |
| 991 | |
| 992 | mediastream_signaling_.SendAudioVideoStream2(); |
| 993 | SessionDescriptionInterface* answer = |
| 994 | CreateRemoteAnswer(session_->local_description()); |
| 995 | SetRemoteDescriptionWithoutError(answer); |
| 996 | |
| 997 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 998 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 999 | |
| 1000 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1001 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1002 | |
| 1003 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1004 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1005 | |
| 1006 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1007 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1008 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1009 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1010 | |
| 1011 | // Create new offer without send streams. |
| 1012 | mediastream_signaling_.SendNothing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1013 | offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1014 | |
| 1015 | // Verify the session id is the same and the session version is |
| 1016 | // increased. |
| 1017 | EXPECT_EQ(session_id_orig, offer->session_id()); |
| 1018 | EXPECT_LT(talk_base::FromString<uint64>(session_version_orig), |
| 1019 | talk_base::FromString<uint64>(offer->session_version())); |
| 1020 | |
| 1021 | SetLocalDescriptionWithoutError(offer); |
| 1022 | |
| 1023 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1024 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1025 | SetRemoteDescriptionWithoutError(answer); |
| 1026 | |
| 1027 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1028 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1029 | |
| 1030 | // Make sure the receive streams have not changed. |
| 1031 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1032 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1033 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1034 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1035 | } |
| 1036 | |
| 1037 | // Test receiving offers and creating answers and make sure the |
| 1038 | // media engine creates the expected send and receive streams. |
| 1039 | TEST_F(WebRtcSessionTest, TestReceiveOfferCreateAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1040 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1041 | mediastream_signaling_.SendAudioVideoStream2(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1042 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1043 | SetRemoteDescriptionWithoutError(offer); |
| 1044 | |
| 1045 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1046 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1047 | SetLocalDescriptionWithoutError(answer); |
| 1048 | |
| 1049 | const std::string session_id_orig = answer->session_id(); |
| 1050 | const std::string session_version_orig = answer->session_version(); |
| 1051 | |
| 1052 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1053 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1054 | |
| 1055 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1056 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1057 | |
| 1058 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1059 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1060 | |
| 1061 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1062 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1063 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1064 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1065 | |
| 1066 | mediastream_signaling_.SendAudioVideoStream1And2(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1067 | offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1068 | SetRemoteDescriptionWithoutError(offer); |
| 1069 | |
| 1070 | // Answer by turning off all send streams. |
| 1071 | mediastream_signaling_.SendNothing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1072 | answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1073 | |
| 1074 | // Verify the session id is the same and the session version is |
| 1075 | // increased. |
| 1076 | EXPECT_EQ(session_id_orig, answer->session_id()); |
| 1077 | EXPECT_LT(talk_base::FromString<uint64>(session_version_orig), |
| 1078 | talk_base::FromString<uint64>(answer->session_version())); |
| 1079 | SetLocalDescriptionWithoutError(answer); |
| 1080 | |
| 1081 | ASSERT_EQ(2u, video_channel_->recv_streams().size()); |
| 1082 | EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id); |
| 1083 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id); |
| 1084 | ASSERT_EQ(2u, voice_channel_->recv_streams().size()); |
| 1085 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id); |
| 1086 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id); |
| 1087 | |
| 1088 | // Make sure we have no send streams. |
| 1089 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1090 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1091 | } |
| 1092 | |
| 1093 | // Test we will return fail when apply an offer that doesn't have |
| 1094 | // crypto enabled. |
| 1095 | TEST_F(WebRtcSessionTest, SetNonCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1096 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1097 | cricket::MediaSessionOptions options; |
| 1098 | options.has_video = true; |
| 1099 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1100 | options, cricket::SEC_DISABLED); |
| 1101 | ASSERT_TRUE(offer != NULL); |
| 1102 | VerifyNoCryptoParams(offer->description(), false); |
| 1103 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1104 | // the offer. |
| 1105 | SetRemoteDescriptionExpectError(kSdpWithoutCrypto, offer); |
| 1106 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1107 | ASSERT_TRUE(offer != NULL); |
| 1108 | SetLocalDescriptionExpectError(kSdpWithoutCrypto, offer); |
| 1109 | } |
| 1110 | |
| 1111 | // Test we will return fail when apply an answer that doesn't have |
| 1112 | // crypto enabled. |
| 1113 | TEST_F(WebRtcSessionTest, SetLocalNonCryptoAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1114 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1115 | SessionDescriptionInterface* offer = NULL; |
| 1116 | SessionDescriptionInterface* answer = NULL; |
| 1117 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1118 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1119 | // the offer. |
| 1120 | SetRemoteDescriptionWithoutError(offer); |
| 1121 | SetLocalDescriptionExpectError(kSdpWithoutCrypto, answer); |
| 1122 | } |
| 1123 | |
| 1124 | // Test we will return fail when apply an answer that doesn't have |
| 1125 | // crypto enabled. |
| 1126 | TEST_F(WebRtcSessionTest, SetRemoteNonCryptoAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1127 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1128 | SessionDescriptionInterface* offer = NULL; |
| 1129 | SessionDescriptionInterface* answer = NULL; |
| 1130 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1131 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1132 | // the offer. |
| 1133 | SetLocalDescriptionWithoutError(offer); |
| 1134 | SetRemoteDescriptionExpectError(kSdpWithoutCrypto, answer); |
| 1135 | } |
| 1136 | |
| 1137 | // Test that we can create and set an offer with a DTLS fingerprint. |
| 1138 | TEST_F(WebRtcSessionTest, CreateSetDtlsOffer) { |
| 1139 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 1140 | InitWithDtls(); |
| 1141 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1142 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1143 | ASSERT_TRUE(offer != NULL); |
| 1144 | VerifyFingerprintStatus(offer->description(), true); |
| 1145 | // SetLocalDescription will take the ownership of the offer. |
| 1146 | SetLocalDescriptionWithoutError(offer); |
| 1147 | } |
| 1148 | |
| 1149 | // Test that we can process an offer with a DTLS fingerprint |
| 1150 | // and that we return an answer with a fingerprint. |
| 1151 | TEST_F(WebRtcSessionTest, ReceiveDtlsOfferCreateAnswer) { |
| 1152 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 1153 | InitWithDtls(); |
| 1154 | SetFactoryDtlsSrtp(); |
| 1155 | cricket::MediaSessionOptions options; |
| 1156 | options.has_video = true; |
| 1157 | JsepSessionDescription* offer = CreateRemoteOffer(options); |
| 1158 | ASSERT_TRUE(offer != NULL); |
| 1159 | VerifyFingerprintStatus(offer->description(), true); |
| 1160 | |
| 1161 | // SetRemoteDescription will take the ownership of the offer. |
| 1162 | SetRemoteDescriptionWithoutError(offer); |
| 1163 | |
| 1164 | // Verify that we get a crypto fingerprint in the answer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1165 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1166 | ASSERT_TRUE(answer != NULL); |
| 1167 | VerifyFingerprintStatus(answer->description(), true); |
| 1168 | // Check that we don't have an a=crypto line in the answer. |
| 1169 | VerifyNoCryptoParams(answer->description(), true); |
| 1170 | |
| 1171 | // Now set the local description, which should work, even without a=crypto. |
| 1172 | SetLocalDescriptionWithoutError(answer); |
| 1173 | } |
| 1174 | |
| 1175 | // Test that even if we support DTLS, if the other side didn't offer a |
| 1176 | // fingerprint, we don't either. |
| 1177 | TEST_F(WebRtcSessionTest, ReceiveNoDtlsOfferCreateAnswer) { |
| 1178 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 1179 | InitWithDtls(); |
| 1180 | cricket::MediaSessionOptions options; |
| 1181 | options.has_video = true; |
| 1182 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1183 | options, cricket::SEC_REQUIRED); |
| 1184 | ASSERT_TRUE(offer != NULL); |
| 1185 | VerifyFingerprintStatus(offer->description(), false); |
| 1186 | |
| 1187 | // SetRemoteDescription will take the ownership of |
| 1188 | // the offer. |
| 1189 | SetRemoteDescriptionWithoutError(offer); |
| 1190 | |
| 1191 | // Verify that we don't get a crypto fingerprint in the answer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1192 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1193 | ASSERT_TRUE(answer != NULL); |
| 1194 | VerifyFingerprintStatus(answer->description(), false); |
| 1195 | |
| 1196 | // Now set the local description. |
| 1197 | SetLocalDescriptionWithoutError(answer); |
| 1198 | } |
| 1199 | |
| 1200 | TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1201 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1202 | mediastream_signaling_.SendNothing(); |
| 1203 | // SetLocalDescription take ownership of offer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1204 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1205 | SetLocalDescriptionWithoutError(offer); |
| 1206 | |
| 1207 | // SetLocalDescription take ownership of offer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1208 | SessionDescriptionInterface* offer2 = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1209 | SetLocalDescriptionWithoutError(offer2); |
| 1210 | } |
| 1211 | |
| 1212 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1213 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1214 | mediastream_signaling_.SendNothing(); |
| 1215 | // SetLocalDescription take ownership of offer. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1216 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1217 | SetRemoteDescriptionWithoutError(offer); |
| 1218 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1219 | SessionDescriptionInterface* offer2 = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1220 | SetRemoteDescriptionWithoutError(offer2); |
| 1221 | } |
| 1222 | |
| 1223 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1224 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1225 | mediastream_signaling_.SendNothing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1226 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1227 | SetLocalDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1228 | offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1229 | SetRemoteDescriptionExpectError( |
| 1230 | "Called with type in wrong state, type: offer state: STATE_SENTINITIATE", |
| 1231 | offer); |
| 1232 | } |
| 1233 | |
| 1234 | TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1235 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1236 | mediastream_signaling_.SendNothing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1237 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1238 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1239 | offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1240 | SetLocalDescriptionExpectError( |
| 1241 | "Called with type in wrong state, type: " |
| 1242 | "offer state: STATE_RECEIVEDINITIATE", |
| 1243 | offer); |
| 1244 | } |
| 1245 | |
| 1246 | TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1247 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1248 | mediastream_signaling_.SendNothing(); |
| 1249 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 1250 | SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE); |
| 1251 | |
| 1252 | JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1253 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1254 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1255 | SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT); |
| 1256 | |
| 1257 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1258 | JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1259 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1260 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1261 | |
| 1262 | SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT); |
| 1263 | |
| 1264 | mediastream_signaling_.SendAudioVideoStream2(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1265 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1266 | SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT); |
| 1267 | } |
| 1268 | |
| 1269 | TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1270 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1271 | mediastream_signaling_.SendNothing(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1272 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1273 | SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE); |
| 1274 | |
| 1275 | JsepSessionDescription* pranswer = |
| 1276 | CreateRemoteAnswer(session_->local_description()); |
| 1277 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1278 | |
| 1279 | SetRemoteDescriptionExpectState(pranswer, |
| 1280 | BaseSession::STATE_RECEIVEDPRACCEPT); |
| 1281 | |
| 1282 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1283 | JsepSessionDescription* pranswer2 = |
| 1284 | CreateRemoteAnswer(session_->local_description()); |
| 1285 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1286 | |
| 1287 | SetRemoteDescriptionExpectState(pranswer2, |
| 1288 | BaseSession::STATE_RECEIVEDPRACCEPT); |
| 1289 | |
| 1290 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1291 | SessionDescriptionInterface* answer = |
| 1292 | CreateRemoteAnswer(session_->local_description()); |
| 1293 | SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT); |
| 1294 | } |
| 1295 | |
| 1296 | TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1297 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1298 | mediastream_signaling_.SendNothing(); |
| 1299 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1300 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1301 | SessionDescriptionInterface* answer = |
| 1302 | CreateRemoteAnswer(offer.get()); |
| 1303 | SetLocalDescriptionExpectError( |
| 1304 | "Called with type in wrong state, type: answer state: STATE_INIT", |
| 1305 | answer); |
| 1306 | } |
| 1307 | |
| 1308 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1309 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1310 | mediastream_signaling_.SendNothing(); |
| 1311 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1312 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1313 | SessionDescriptionInterface* answer = |
| 1314 | CreateRemoteAnswer(offer.get()); |
| 1315 | SetRemoteDescriptionExpectError( |
| 1316 | "Called with type in wrong state, type: answer state: STATE_INIT", |
| 1317 | answer); |
| 1318 | } |
| 1319 | |
| 1320 | TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1321 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1322 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1323 | |
| 1324 | cricket::Candidate candidate; |
| 1325 | candidate.set_component(1); |
| 1326 | JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); |
| 1327 | |
| 1328 | // Fail since we have not set a offer description. |
| 1329 | EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1330 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1331 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1332 | SetLocalDescriptionWithoutError(offer); |
| 1333 | // Candidate should be allowed to add before remote description. |
| 1334 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1335 | candidate.set_component(2); |
| 1336 | JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); |
| 1337 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 1338 | |
| 1339 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 1340 | session_->local_description()); |
| 1341 | SetRemoteDescriptionWithoutError(answer); |
| 1342 | |
| 1343 | // Verifying the candidates are copied properly from internal vector. |
| 1344 | const SessionDescriptionInterface* remote_desc = |
| 1345 | session_->remote_description(); |
| 1346 | ASSERT_TRUE(remote_desc != NULL); |
| 1347 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1348 | const IceCandidateCollection* candidates = |
| 1349 | remote_desc->candidates(kMediaContentIndex0); |
| 1350 | ASSERT_EQ(2u, candidates->count()); |
| 1351 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1352 | EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); |
| 1353 | EXPECT_EQ(1, candidates->at(0)->candidate().component()); |
| 1354 | EXPECT_EQ(2, candidates->at(1)->candidate().component()); |
| 1355 | |
| 1356 | candidate.set_component(2); |
| 1357 | JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); |
| 1358 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); |
| 1359 | ASSERT_EQ(3u, candidates->count()); |
| 1360 | |
| 1361 | JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); |
| 1362 | EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); |
| 1363 | } |
| 1364 | |
| 1365 | // Test that a remote candidate is added to the remote session description and |
| 1366 | // that it is retained if the remote session description is changed. |
| 1367 | TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1368 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1369 | cricket::Candidate candidate1; |
| 1370 | candidate1.set_component(1); |
| 1371 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 1372 | candidate1); |
| 1373 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1374 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1375 | |
| 1376 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1377 | const SessionDescriptionInterface* remote_desc = |
| 1378 | session_->remote_description(); |
| 1379 | ASSERT_TRUE(remote_desc != NULL); |
| 1380 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1381 | const IceCandidateCollection* candidates = |
| 1382 | remote_desc->candidates(kMediaContentIndex0); |
| 1383 | ASSERT_EQ(1u, candidates->count()); |
| 1384 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1385 | |
| 1386 | // Update the RemoteSessionDescription with a new session description and |
| 1387 | // a candidate and check that the new remote session description contains both |
| 1388 | // candidates. |
| 1389 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 1390 | cricket::Candidate candidate2; |
| 1391 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 1392 | candidate2); |
| 1393 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 1394 | SetRemoteDescriptionWithoutError(offer); |
| 1395 | |
| 1396 | remote_desc = session_->remote_description(); |
| 1397 | ASSERT_TRUE(remote_desc != NULL); |
| 1398 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1399 | candidates = remote_desc->candidates(kMediaContentIndex0); |
| 1400 | ASSERT_EQ(2u, candidates->count()); |
| 1401 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1402 | // Username and password have be updated with the TransportInfo of the |
| 1403 | // SessionDescription, won't be equal to the original one. |
| 1404 | candidate2.set_username(candidates->at(0)->candidate().username()); |
| 1405 | candidate2.set_password(candidates->at(0)->candidate().password()); |
| 1406 | EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate())); |
| 1407 | EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index()); |
| 1408 | // No need to verify the username and password. |
| 1409 | candidate1.set_username(candidates->at(1)->candidate().username()); |
| 1410 | candidate1.set_password(candidates->at(1)->candidate().password()); |
| 1411 | EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); |
| 1412 | |
| 1413 | // Test that the candidate is ignored if we can add the same candidate again. |
| 1414 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 1415 | } |
| 1416 | |
| 1417 | // Test that local candidates are added to the local session description and |
| 1418 | // that they are retained if the local session description is changed. |
| 1419 | TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) { |
| 1420 | AddInterface(kClientAddr1); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1421 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1422 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1423 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1424 | |
| 1425 | const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 1426 | const IceCandidateCollection* candidates = |
| 1427 | local_desc->candidates(kMediaContentIndex0); |
| 1428 | ASSERT_TRUE(candidates != NULL); |
| 1429 | EXPECT_EQ(0u, candidates->count()); |
| 1430 | |
| 1431 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1432 | |
| 1433 | local_desc = session_->local_description(); |
| 1434 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 1435 | ASSERT_TRUE(candidates != NULL); |
| 1436 | EXPECT_LT(0u, candidates->count()); |
| 1437 | candidates = local_desc->candidates(1); |
| 1438 | ASSERT_TRUE(candidates != NULL); |
| 1439 | EXPECT_LT(0u, candidates->count()); |
| 1440 | |
| 1441 | // Update the session descriptions. |
| 1442 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1443 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1444 | |
| 1445 | local_desc = session_->local_description(); |
| 1446 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 1447 | ASSERT_TRUE(candidates != NULL); |
| 1448 | EXPECT_LT(0u, candidates->count()); |
| 1449 | candidates = local_desc->candidates(1); |
| 1450 | ASSERT_TRUE(candidates != NULL); |
| 1451 | EXPECT_LT(0u, candidates->count()); |
| 1452 | } |
| 1453 | |
| 1454 | // Test that we can set a remote session description with remote candidates. |
| 1455 | TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1456 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1457 | |
| 1458 | cricket::Candidate candidate1; |
| 1459 | candidate1.set_component(1); |
| 1460 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 1461 | candidate1); |
| 1462 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1463 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1464 | |
| 1465 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 1466 | SetRemoteDescriptionWithoutError(offer); |
| 1467 | |
| 1468 | const SessionDescriptionInterface* remote_desc = |
| 1469 | session_->remote_description(); |
| 1470 | ASSERT_TRUE(remote_desc != NULL); |
| 1471 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1472 | const IceCandidateCollection* candidates = |
| 1473 | remote_desc->candidates(kMediaContentIndex0); |
| 1474 | ASSERT_EQ(1u, candidates->count()); |
| 1475 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1476 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1477 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1478 | SetLocalDescriptionWithoutError(answer); |
| 1479 | } |
| 1480 | |
| 1481 | // Test that offers and answers contains ice candidates when Ice candidates have |
| 1482 | // been gathered. |
| 1483 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) { |
| 1484 | AddInterface(kClientAddr1); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1485 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1486 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1487 | // Ice is started but candidates are not provided until SetLocalDescription |
| 1488 | // is called. |
| 1489 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 1490 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 1491 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1492 | // Wait until at least one local candidate has been collected. |
| 1493 | EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(), |
| 1494 | kIceCandidatesTimeout); |
| 1495 | EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(), |
| 1496 | kIceCandidatesTimeout); |
| 1497 | |
| 1498 | talk_base::scoped_ptr<SessionDescriptionInterface> local_offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1499 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1500 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL); |
| 1501 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count()); |
| 1502 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL); |
| 1503 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count()); |
| 1504 | |
| 1505 | SessionDescriptionInterface* remote_offer(CreateRemoteOffer()); |
| 1506 | SetRemoteDescriptionWithoutError(remote_offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1507 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1508 | ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL); |
| 1509 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count()); |
| 1510 | ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL); |
| 1511 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count()); |
| 1512 | SetLocalDescriptionWithoutError(answer); |
| 1513 | } |
| 1514 | |
| 1515 | // Verifies TransportProxy and media channels are created with content names |
| 1516 | // present in the SessionDescription. |
| 1517 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1518 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1519 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1520 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1521 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1522 | |
| 1523 | // CreateOffer creates session description with the content names "audio" and |
| 1524 | // "video". Goal is to modify these content names and verify transport channel |
| 1525 | // proxy in the BaseSession, as proxies are created with the content names |
| 1526 | // present in SDP. |
| 1527 | std::string sdp; |
| 1528 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 1529 | const std::string kAudioMid = "a=mid:audio"; |
| 1530 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 1531 | const std::string kVideoMid = "a=mid:video"; |
| 1532 | const std::string kVideoMidReplaceStr = "a=mid:video_content_name"; |
| 1533 | |
| 1534 | // Replacing |audio| with |audio_content_name|. |
| 1535 | talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
| 1536 | kAudioMidReplaceStr.c_str(), |
| 1537 | kAudioMidReplaceStr.length(), |
| 1538 | &sdp); |
| 1539 | // Replacing |video| with |video_content_name|. |
| 1540 | talk_base::replace_substrs(kVideoMid.c_str(), kVideoMid.length(), |
| 1541 | kVideoMidReplaceStr.c_str(), |
| 1542 | kVideoMidReplaceStr.length(), |
| 1543 | &sdp); |
| 1544 | |
| 1545 | SessionDescriptionInterface* modified_offer = |
| 1546 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 1547 | |
| 1548 | SetRemoteDescriptionWithoutError(modified_offer); |
| 1549 | |
| 1550 | SessionDescriptionInterface* answer = |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1551 | CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1552 | SetLocalDescriptionWithoutError(answer); |
| 1553 | |
| 1554 | EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL); |
| 1555 | EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL); |
| 1556 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 1557 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 1558 | } |
| 1559 | |
| 1560 | // Test that an offer contains the correct media content descriptions based on |
| 1561 | // the send streams when no constraints have been set. |
| 1562 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1563 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1564 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1565 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1566 | ASSERT_TRUE(offer != NULL); |
| 1567 | const cricket::ContentInfo* content = |
| 1568 | cricket::GetFirstAudioContent(offer->description()); |
| 1569 | EXPECT_TRUE(content != NULL); |
| 1570 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1571 | EXPECT_TRUE(content == NULL); |
| 1572 | } |
| 1573 | |
| 1574 | // Test that an offer contains the correct media content descriptions based on |
| 1575 | // the send streams when no constraints have been set. |
| 1576 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1577 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1578 | // Test Audio only offer. |
| 1579 | mediastream_signaling_.UseOptionsAudioOnly(); |
| 1580 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1581 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1582 | const cricket::ContentInfo* content = |
| 1583 | cricket::GetFirstAudioContent(offer->description()); |
| 1584 | EXPECT_TRUE(content != NULL); |
| 1585 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1586 | EXPECT_TRUE(content == NULL); |
| 1587 | |
| 1588 | // Test Audio / Video offer. |
| 1589 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1590 | offer.reset(CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1591 | content = cricket::GetFirstAudioContent(offer->description()); |
| 1592 | EXPECT_TRUE(content != NULL); |
| 1593 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1594 | EXPECT_TRUE(content != NULL); |
| 1595 | } |
| 1596 | |
| 1597 | // Test that an offer contains no media content descriptions if |
| 1598 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 1599 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1600 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1601 | webrtc::FakeConstraints constraints_no_receive; |
| 1602 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 1603 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 1604 | |
| 1605 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1606 | CreateOffer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1607 | ASSERT_TRUE(offer != NULL); |
| 1608 | const cricket::ContentInfo* content = |
| 1609 | cricket::GetFirstAudioContent(offer->description()); |
| 1610 | EXPECT_TRUE(content == NULL); |
| 1611 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1612 | EXPECT_TRUE(content == NULL); |
| 1613 | } |
| 1614 | |
| 1615 | // Test that an offer contains only audio media content descriptions if |
| 1616 | // kOfferToReceiveAudio constraints are set to true. |
| 1617 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1618 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1619 | webrtc::FakeConstraints constraints_audio_only; |
| 1620 | constraints_audio_only.SetMandatoryReceiveAudio(true); |
| 1621 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1622 | CreateOffer(&constraints_audio_only)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | |
| 1624 | const cricket::ContentInfo* content = |
| 1625 | cricket::GetFirstAudioContent(offer->description()); |
| 1626 | EXPECT_TRUE(content != NULL); |
| 1627 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1628 | EXPECT_TRUE(content == NULL); |
| 1629 | } |
| 1630 | |
| 1631 | // Test that an offer contains audio and video media content descriptions if |
| 1632 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 1633 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1634 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1635 | // Test Audio / Video offer. |
| 1636 | webrtc::FakeConstraints constraints_audio_video; |
| 1637 | constraints_audio_video.SetMandatoryReceiveAudio(true); |
| 1638 | constraints_audio_video.SetMandatoryReceiveVideo(true); |
| 1639 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1640 | CreateOffer(&constraints_audio_video)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1641 | const cricket::ContentInfo* content = |
| 1642 | cricket::GetFirstAudioContent(offer->description()); |
| 1643 | |
| 1644 | EXPECT_TRUE(content != NULL); |
| 1645 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1646 | EXPECT_TRUE(content != NULL); |
| 1647 | |
| 1648 | // TODO(perkj): Should the direction be set to SEND_ONLY if |
| 1649 | // The constraints is set to not receive audio or video but a track is added? |
| 1650 | } |
| 1651 | |
| 1652 | // Test that an answer can not be created if the last remote description is not |
| 1653 | // an offer. |
| 1654 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1655 | Init(NULL); |
| 1656 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1657 | SetLocalDescriptionWithoutError(offer); |
| 1658 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 1659 | SetRemoteDescriptionWithoutError(answer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1660 | EXPECT_TRUE(CreateAnswer(NULL) == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | // Test that an answer contains the correct media content descriptions when no |
| 1664 | // constraints have been set. |
| 1665 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1666 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1667 | // Create a remote offer with audio and video content. |
| 1668 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1669 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1670 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1671 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1672 | const cricket::ContentInfo* content = |
| 1673 | cricket::GetFirstAudioContent(answer->description()); |
| 1674 | ASSERT_TRUE(content != NULL); |
| 1675 | EXPECT_FALSE(content->rejected); |
| 1676 | |
| 1677 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1678 | ASSERT_TRUE(content != NULL); |
| 1679 | EXPECT_FALSE(content->rejected); |
| 1680 | } |
| 1681 | |
| 1682 | // Test that an answer contains the correct media content descriptions when no |
| 1683 | // constraints have been set and the offer only contain audio. |
| 1684 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1685 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1686 | // Create a remote offer with audio only. |
| 1687 | cricket::MediaSessionOptions options; |
| 1688 | options.has_audio = true; |
| 1689 | options.has_video = false; |
| 1690 | talk_base::scoped_ptr<JsepSessionDescription> offer( |
| 1691 | CreateRemoteOffer(options)); |
| 1692 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 1693 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 1694 | |
| 1695 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1696 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1697 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1698 | const cricket::ContentInfo* content = |
| 1699 | cricket::GetFirstAudioContent(answer->description()); |
| 1700 | ASSERT_TRUE(content != NULL); |
| 1701 | EXPECT_FALSE(content->rejected); |
| 1702 | |
| 1703 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 1704 | } |
| 1705 | |
| 1706 | // Test that an answer contains the correct media content descriptions when no |
| 1707 | // constraints have been set. |
| 1708 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1709 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1710 | // Create a remote offer with audio and video content. |
| 1711 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1712 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1713 | // Test with a stream with tracks. |
| 1714 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1715 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1716 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1717 | const cricket::ContentInfo* content = |
| 1718 | cricket::GetFirstAudioContent(answer->description()); |
| 1719 | ASSERT_TRUE(content != NULL); |
| 1720 | EXPECT_FALSE(content->rejected); |
| 1721 | |
| 1722 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1723 | ASSERT_TRUE(content != NULL); |
| 1724 | EXPECT_FALSE(content->rejected); |
| 1725 | } |
| 1726 | |
| 1727 | // Test that an answer contains the correct media content descriptions when |
| 1728 | // constraints have been set but no stream is sent. |
| 1729 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1730 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1731 | // Create a remote offer with audio and video content. |
| 1732 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1733 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1734 | |
| 1735 | webrtc::FakeConstraints constraints_no_receive; |
| 1736 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 1737 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 1738 | |
| 1739 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1740 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1741 | const cricket::ContentInfo* content = |
| 1742 | cricket::GetFirstAudioContent(answer->description()); |
| 1743 | ASSERT_TRUE(content != NULL); |
| 1744 | EXPECT_TRUE(content->rejected); |
| 1745 | |
| 1746 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1747 | ASSERT_TRUE(content != NULL); |
| 1748 | EXPECT_TRUE(content->rejected); |
| 1749 | } |
| 1750 | |
| 1751 | // Test that an answer contains the correct media content descriptions when |
| 1752 | // constraints have been set and streams are sent. |
| 1753 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1754 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1755 | // Create a remote offer with audio and video content. |
| 1756 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1757 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1758 | |
| 1759 | webrtc::FakeConstraints constraints_no_receive; |
| 1760 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 1761 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 1762 | |
| 1763 | // Test with a stream with tracks. |
| 1764 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1765 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1766 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1767 | |
| 1768 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1769 | const cricket::ContentInfo* content = |
| 1770 | cricket::GetFirstAudioContent(answer->description()); |
| 1771 | ASSERT_TRUE(content != NULL); |
| 1772 | EXPECT_FALSE(content->rejected); |
| 1773 | |
| 1774 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1775 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1776 | ASSERT_TRUE(content != NULL); |
| 1777 | EXPECT_FALSE(content->rejected); |
| 1778 | } |
| 1779 | |
| 1780 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 1781 | AddCNCodecs(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1782 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1783 | webrtc::FakeConstraints constraints; |
| 1784 | constraints.SetOptionalVAD(false); |
| 1785 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1786 | CreateOffer(&constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1787 | const cricket::ContentInfo* content = |
| 1788 | cricket::GetFirstAudioContent(offer->description()); |
| 1789 | EXPECT_TRUE(content != NULL); |
| 1790 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1791 | } |
| 1792 | |
| 1793 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 1794 | AddCNCodecs(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1795 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1796 | // Create a remote offer with audio and video content. |
| 1797 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1798 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1799 | |
| 1800 | webrtc::FakeConstraints constraints; |
| 1801 | constraints.SetOptionalVAD(false); |
| 1802 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1803 | CreateAnswer(&constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1804 | const cricket::ContentInfo* content = |
| 1805 | cricket::GetFirstAudioContent(answer->description()); |
| 1806 | ASSERT_TRUE(content != NULL); |
| 1807 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1808 | } |
| 1809 | |
| 1810 | // This test verifies the call setup when remote answer with audio only and |
| 1811 | // later updates with video. |
| 1812 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1813 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1814 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 1815 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 1816 | |
| 1817 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1818 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1819 | |
| 1820 | cricket::MediaSessionOptions options; |
| 1821 | options.has_video = false; |
| 1822 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 1823 | |
| 1824 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1825 | // and answer; |
| 1826 | SetLocalDescriptionWithoutError(offer); |
| 1827 | SetRemoteDescriptionWithoutError(answer); |
| 1828 | |
| 1829 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1830 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1831 | |
| 1832 | ASSERT_TRUE(video_channel_ == NULL); |
| 1833 | |
| 1834 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 1835 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1836 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 1837 | |
| 1838 | // Let the remote end update the session descriptions, with Audio and Video. |
| 1839 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1840 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1841 | |
| 1842 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1843 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1844 | |
| 1845 | ASSERT_TRUE(video_channel_ != NULL); |
| 1846 | ASSERT_TRUE(voice_channel_ != NULL); |
| 1847 | |
| 1848 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1849 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1850 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 1851 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 1852 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1853 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1854 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1855 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1856 | |
| 1857 | // Change session back to audio only. |
| 1858 | mediastream_signaling_.UseOptionsAudioOnly(); |
| 1859 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1860 | |
| 1861 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 1862 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1863 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1864 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1865 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1866 | } |
| 1867 | |
| 1868 | // This test verifies the call setup when remote answer with video only and |
| 1869 | // later updates with audio. |
| 1870 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1871 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1872 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 1873 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 1874 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1875 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1876 | |
| 1877 | cricket::MediaSessionOptions options; |
| 1878 | options.has_audio = false; |
| 1879 | options.has_video = true; |
| 1880 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 1881 | offer, options, cricket::SEC_ENABLED); |
| 1882 | |
| 1883 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1884 | // and answer. |
| 1885 | SetLocalDescriptionWithoutError(offer); |
| 1886 | SetRemoteDescriptionWithoutError(answer); |
| 1887 | |
| 1888 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1889 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1890 | |
| 1891 | ASSERT_TRUE(voice_channel_ == NULL); |
| 1892 | ASSERT_TRUE(video_channel_ != NULL); |
| 1893 | |
| 1894 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 1895 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1896 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 1897 | |
| 1898 | // Update the session descriptions, with Audio and Video. |
| 1899 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1900 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1901 | |
| 1902 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1903 | ASSERT_TRUE(voice_channel_ != NULL); |
| 1904 | |
| 1905 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1906 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1907 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1908 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1909 | |
| 1910 | // Change session back to video only. |
| 1911 | mediastream_signaling_.UseOptionsVideoOnly(); |
| 1912 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1913 | |
| 1914 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1915 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1916 | |
| 1917 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1918 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 1919 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1920 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 1921 | } |
| 1922 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1923 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1924 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1925 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1926 | scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1927 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1928 | VerifyCryptoParams(offer->description()); |
| 1929 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1930 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1931 | VerifyCryptoParams(answer->description()); |
| 1932 | } |
| 1933 | |
| 1934 | TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 1935 | constraints_.reset(new FakeConstraints()); |
| 1936 | constraints_->AddOptional( |
| 1937 | webrtc::MediaConstraintsInterface::kInternalDisableEncryption, true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1938 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1939 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1940 | scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1941 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1942 | VerifyNoCryptoParams(offer->description(), false); |
| 1943 | } |
| 1944 | |
| 1945 | TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1946 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1947 | VerifyAnswerFromNonCryptoOffer(); |
| 1948 | } |
| 1949 | |
| 1950 | TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1951 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1952 | VerifyAnswerFromCryptoOffer(); |
| 1953 | } |
| 1954 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 1955 | // This test verifies that setLocalDescription fails if |
| 1956 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 1957 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) { |
| 1958 | Init(NULL); |
| 1959 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1960 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 1961 | std::string sdp; |
| 1962 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 1963 | SessionDescriptionInterface* modified_offer = |
| 1964 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 1965 | SetLocalDescriptionExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
| 1966 | } |
| 1967 | |
| 1968 | // This test verifies that setRemoteDescription fails if |
| 1969 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 1970 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) { |
| 1971 | Init(NULL); |
| 1972 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 1973 | std::string sdp; |
| 1974 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 1975 | SessionDescriptionInterface* modified_offer = |
| 1976 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 1977 | SetRemoteDescriptionExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
| 1978 | } |
| 1979 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1980 | TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) { |
| 1981 | // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in |
| 1982 | // local description is removed by the application, BUNDLE flag should be |
| 1983 | // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1984 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1985 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 1986 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 1987 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1988 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1989 | cricket::SessionDescription* offer_copy = |
| 1990 | offer->description()->Copy(); |
| 1991 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1992 | JsepSessionDescription* modified_offer = |
| 1993 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 1994 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 1995 | |
| 1996 | SetLocalDescriptionWithoutError(modified_offer); |
| 1997 | EXPECT_FALSE(allocator_.flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 1998 | } |
| 1999 | |
| 2000 | TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2001 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2002 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2003 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2004 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2005 | FakeConstraints constraints; |
| 2006 | constraints.SetMandatoryUseRtpMux(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2007 | SessionDescriptionInterface* offer = CreateOffer(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2008 | SetLocalDescriptionWithoutError(offer); |
| 2009 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2010 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 2011 | CreateRemoteAnswer(session_->local_description())); |
| 2012 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2013 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2014 | JsepSessionDescription* modified_answer = |
| 2015 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2016 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2017 | SetRemoteDescriptionWithoutError(modified_answer); |
| 2018 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2019 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2020 | |
| 2021 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2022 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2023 | |
| 2024 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2025 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 2026 | |
| 2027 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2028 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 2029 | |
| 2030 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2031 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 2032 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2033 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 2034 | } |
| 2035 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2036 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 2037 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 2038 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2039 | WebRtcSessionTest::Init(NULL); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2040 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2041 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2042 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2043 | FakeConstraints constraints; |
| 2044 | constraints.SetMandatoryUseRtpMux(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2045 | SessionDescriptionInterface* offer = CreateOffer(&constraints); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2046 | std::string offer_str; |
| 2047 | offer->ToString(&offer_str); |
| 2048 | // Disable rtcp-mux |
| 2049 | const std::string rtcp_mux = "rtcp-mux"; |
| 2050 | const std::string xrtcp_mux = "xrtcp-mux"; |
| 2051 | talk_base::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
| 2052 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 2053 | &offer_str); |
| 2054 | JsepSessionDescription *local_offer = |
| 2055 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2056 | EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
| 2057 | SetLocalDescriptionExpectError(kBundleWithoutRtcpMux, local_offer); |
| 2058 | JsepSessionDescription *remote_offer = |
| 2059 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2060 | EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
| 2061 | SetRemoteDescriptionExpectError(kBundleWithoutRtcpMux, remote_offer); |
| 2062 | // Trying unmodified SDP. |
| 2063 | SetLocalDescriptionWithoutError(offer); |
| 2064 | } |
| 2065 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2066 | TEST_F(WebRtcSessionTest, SetAudioPlayout) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2067 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2068 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2069 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2070 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2071 | ASSERT_TRUE(channel != NULL); |
| 2072 | ASSERT_EQ(1u, channel->recv_streams().size()); |
| 2073 | uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
| 2074 | double left_vol, right_vol; |
| 2075 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2076 | EXPECT_EQ(1, left_vol); |
| 2077 | EXPECT_EQ(1, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2078 | talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
| 2079 | session_->SetAudioPlayout(receive_ssrc, false, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2080 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2081 | EXPECT_EQ(0, left_vol); |
| 2082 | EXPECT_EQ(0, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2083 | EXPECT_EQ(0, renderer->channel_id()); |
| 2084 | session_->SetAudioPlayout(receive_ssrc, true, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2085 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2086 | EXPECT_EQ(1, left_vol); |
| 2087 | EXPECT_EQ(1, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2088 | EXPECT_EQ(-1, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | TEST_F(WebRtcSessionTest, SetAudioSend) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2092 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2093 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2094 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2095 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2096 | ASSERT_TRUE(channel != NULL); |
| 2097 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2098 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2099 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2100 | |
| 2101 | cricket::AudioOptions options; |
| 2102 | options.echo_cancellation.Set(true); |
| 2103 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2104 | talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
| 2105 | session_->SetAudioSend(send_ssrc, false, options, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2106 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 2107 | EXPECT_FALSE(channel->options().echo_cancellation.IsSet()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2108 | EXPECT_EQ(0, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2109 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2110 | session_->SetAudioSend(send_ssrc, true, options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2111 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2112 | bool value; |
| 2113 | EXPECT_TRUE(channel->options().echo_cancellation.Get(&value)); |
| 2114 | EXPECT_TRUE(value); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2115 | EXPECT_EQ(-1, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | TEST_F(WebRtcSessionTest, SetVideoPlayout) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2119 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2120 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2121 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2122 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 2123 | ASSERT_TRUE(channel != NULL); |
| 2124 | ASSERT_LT(0u, channel->renderers().size()); |
| 2125 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 2126 | ASSERT_EQ(1u, channel->recv_streams().size()); |
| 2127 | uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
| 2128 | cricket::FakeVideoRenderer renderer; |
| 2129 | session_->SetVideoPlayout(receive_ssrc, true, &renderer); |
| 2130 | EXPECT_TRUE(channel->renderers().begin()->second == &renderer); |
| 2131 | session_->SetVideoPlayout(receive_ssrc, false, &renderer); |
| 2132 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 2133 | } |
| 2134 | |
| 2135 | TEST_F(WebRtcSessionTest, SetVideoSend) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2136 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2137 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2138 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2139 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 2140 | ASSERT_TRUE(channel != NULL); |
| 2141 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2142 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2143 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2144 | cricket::VideoOptions* options = NULL; |
| 2145 | session_->SetVideoSend(send_ssrc, false, options); |
| 2146 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 2147 | session_->SetVideoSend(send_ssrc, true, options); |
| 2148 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2149 | } |
| 2150 | |
| 2151 | TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { |
| 2152 | TestCanInsertDtmf(false); |
| 2153 | } |
| 2154 | |
| 2155 | TEST_F(WebRtcSessionTest, CanInsertDtmf) { |
| 2156 | TestCanInsertDtmf(true); |
| 2157 | } |
| 2158 | |
| 2159 | TEST_F(WebRtcSessionTest, InsertDtmf) { |
| 2160 | // Setup |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2161 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2162 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2163 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2164 | FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2165 | EXPECT_EQ(0U, channel->dtmf_info_queue().size()); |
| 2166 | |
| 2167 | // Insert DTMF |
| 2168 | const int expected_flags = DF_SEND; |
| 2169 | const int expected_duration = 90; |
| 2170 | session_->InsertDtmf(kAudioTrack1, 0, expected_duration); |
| 2171 | session_->InsertDtmf(kAudioTrack1, 1, expected_duration); |
| 2172 | session_->InsertDtmf(kAudioTrack1, 2, expected_duration); |
| 2173 | |
| 2174 | // Verify |
| 2175 | ASSERT_EQ(3U, channel->dtmf_info_queue().size()); |
| 2176 | const uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2177 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0, |
| 2178 | expected_duration, expected_flags)); |
| 2179 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1, |
| 2180 | expected_duration, expected_flags)); |
| 2181 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2, |
| 2182 | expected_duration, expected_flags)); |
| 2183 | } |
| 2184 | |
| 2185 | // This test verifies the |initiator| flag when session initiates the call. |
| 2186 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2187 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2188 | EXPECT_FALSE(session_->initiator()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2189 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2190 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2191 | SetLocalDescriptionWithoutError(offer); |
| 2192 | EXPECT_TRUE(session_->initiator()); |
| 2193 | SetRemoteDescriptionWithoutError(answer); |
| 2194 | EXPECT_TRUE(session_->initiator()); |
| 2195 | } |
| 2196 | |
| 2197 | // This test verifies the |initiator| flag when session receives the call. |
| 2198 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2199 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2200 | EXPECT_FALSE(session_->initiator()); |
| 2201 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2202 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2203 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2204 | |
| 2205 | EXPECT_FALSE(session_->initiator()); |
| 2206 | SetLocalDescriptionWithoutError(answer); |
| 2207 | EXPECT_FALSE(session_->initiator()); |
| 2208 | } |
| 2209 | |
| 2210 | // This test verifies the ice protocol type at initiator of the call |
| 2211 | // if |a=ice-options:google-ice| is present in answer. |
| 2212 | TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2213 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2214 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2215 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 2216 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2217 | CreateRemoteAnswer(offer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2218 | SetLocalDescriptionWithoutError(offer); |
| 2219 | std::string sdp; |
| 2220 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2221 | // Adding ice-options to the session level. |
| 2222 | InjectAfter("t=0 0\r\n", |
| 2223 | "a=ice-options:google-ice\r\n", |
| 2224 | &sdp); |
| 2225 | SessionDescriptionInterface* answer_with_gice = |
| 2226 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2227 | SetRemoteDescriptionWithoutError(answer_with_gice); |
| 2228 | VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE); |
| 2229 | VerifyTransportType("video", cricket::ICEPROTO_GOOGLE); |
| 2230 | } |
| 2231 | |
| 2232 | // This test verifies the ice protocol type at initiator of the call |
| 2233 | // if ICE RFC5245 is supported in answer. |
| 2234 | TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2235 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2236 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2237 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2238 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2239 | SetLocalDescriptionWithoutError(offer); |
| 2240 | |
| 2241 | SetRemoteDescriptionWithoutError(answer); |
| 2242 | VerifyTransportType("audio", cricket::ICEPROTO_RFC5245); |
| 2243 | VerifyTransportType("video", cricket::ICEPROTO_RFC5245); |
| 2244 | } |
| 2245 | |
| 2246 | // This test verifies the ice protocol type at receiver side of the call if |
| 2247 | // receiver decides to use google-ice. |
| 2248 | TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2249 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2250 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2251 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2252 | SetRemoteDescriptionWithoutError(offer); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 2253 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2254 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2255 | std::string sdp; |
| 2256 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2257 | // Adding ice-options to the session level. |
| 2258 | InjectAfter("t=0 0\r\n", |
| 2259 | "a=ice-options:google-ice\r\n", |
| 2260 | &sdp); |
| 2261 | SessionDescriptionInterface* answer_with_gice = |
| 2262 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2263 | SetLocalDescriptionWithoutError(answer_with_gice); |
| 2264 | VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE); |
| 2265 | VerifyTransportType("video", cricket::ICEPROTO_GOOGLE); |
| 2266 | } |
| 2267 | |
| 2268 | // This test verifies the ice protocol type at receiver side of the call if |
| 2269 | // receiver decides to use ice RFC 5245. |
| 2270 | TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2271 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2272 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2273 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2274 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2275 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2276 | SetLocalDescriptionWithoutError(answer); |
| 2277 | VerifyTransportType("audio", cricket::ICEPROTO_RFC5245); |
| 2278 | VerifyTransportType("video", cricket::ICEPROTO_RFC5245); |
| 2279 | } |
| 2280 | |
| 2281 | // This test verifies the session state when ICE RFC5245 in offer and |
| 2282 | // ICE google-ice in answer. |
| 2283 | TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2284 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2285 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2286 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2287 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2288 | std::string offer_str; |
| 2289 | offer->ToString(&offer_str); |
| 2290 | // Disable google-ice |
| 2291 | const std::string gice_option = "google-ice"; |
| 2292 | const std::string xgoogle_xice = "xgoogle-xice"; |
| 2293 | talk_base::replace_substrs(gice_option.c_str(), gice_option.length(), |
| 2294 | xgoogle_xice.c_str(), xgoogle_xice.length(), |
| 2295 | &offer_str); |
| 2296 | JsepSessionDescription *ice_only_offer = |
| 2297 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2298 | EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL)); |
| 2299 | SetLocalDescriptionWithoutError(ice_only_offer); |
| 2300 | std::string original_offer_sdp; |
| 2301 | EXPECT_TRUE(offer->ToString(&original_offer_sdp)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2302 | SessionDescriptionInterface* pranswer_with_gice = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2303 | CreateSessionDescription(JsepSessionDescription::kPrAnswer, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2304 | original_offer_sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2305 | SetRemoteDescriptionExpectError(kPushDownPranswerTDFailed, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2306 | pranswer_with_gice); |
| 2307 | SessionDescriptionInterface* answer_with_gice = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2308 | CreateSessionDescription(JsepSessionDescription::kAnswer, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2309 | original_offer_sdp, NULL); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 2310 | SetRemoteDescriptionExpectError(kPushDownAnswerTDFailed, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2311 | answer_with_gice); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 2315 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2316 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2317 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2318 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2319 | SetLocalDescriptionWithoutError(offer); |
| 2320 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 2321 | CreateRemoteAnswer(session_->local_description())); |
| 2322 | |
| 2323 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2324 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2325 | JsepSessionDescription* modified_answer = |
| 2326 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2327 | |
| 2328 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2329 | answer->session_id(), |
| 2330 | answer->session_version())); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2331 | SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2332 | |
| 2333 | // Modifying content names. |
| 2334 | std::string sdp; |
| 2335 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2336 | const std::string kAudioMid = "a=mid:audio"; |
| 2337 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 2338 | |
| 2339 | // Replacing |audio| with |audio_content_name|. |
| 2340 | talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
| 2341 | kAudioMidReplaceStr.c_str(), |
| 2342 | kAudioMidReplaceStr.length(), |
| 2343 | &sdp); |
| 2344 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2345 | SessionDescriptionInterface* modified_answer1 = |
| 2346 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2347 | SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2348 | |
| 2349 | SetRemoteDescriptionWithoutError(answer.release()); |
| 2350 | } |
| 2351 | |
| 2352 | // Verifying remote offer and local answer have matching m-lines as per |
| 2353 | // RFC 3264. |
| 2354 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2355 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2356 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2357 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2358 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2359 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2360 | |
| 2361 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2362 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2363 | JsepSessionDescription* modified_answer = |
| 2364 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2365 | |
| 2366 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2367 | answer->session_id(), |
| 2368 | answer->session_version())); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2369 | SetLocalDescriptionExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2370 | SetLocalDescriptionWithoutError(answer); |
| 2371 | } |
| 2372 | |
| 2373 | // This test verifies that WebRtcSession does not start candidate allocation |
| 2374 | // before SetLocalDescription is called. |
| 2375 | TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2376 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2377 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2378 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2379 | cricket::Candidate candidate; |
| 2380 | candidate.set_component(1); |
| 2381 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2382 | candidate); |
| 2383 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2384 | cricket::Candidate candidate1; |
| 2385 | candidate1.set_component(1); |
| 2386 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2387 | candidate1); |
| 2388 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 2389 | SetRemoteDescriptionWithoutError(offer); |
| 2390 | ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL); |
| 2391 | ASSERT_TRUE(session_->GetTransportProxy("video") != NULL); |
| 2392 | |
| 2393 | // Pump for 1 second and verify that no candidates are generated. |
| 2394 | talk_base::Thread::Current()->ProcessMessages(1000); |
| 2395 | EXPECT_TRUE(observer_.mline_0_candidates_.empty()); |
| 2396 | EXPECT_TRUE(observer_.mline_1_candidates_.empty()); |
| 2397 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2398 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2399 | SetLocalDescriptionWithoutError(answer); |
| 2400 | EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated()); |
| 2401 | EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated()); |
| 2402 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 2403 | } |
| 2404 | |
| 2405 | // This test verifies that crypto parameter is updated in local session |
| 2406 | // description as per security policy set in MediaSessionDescriptionFactory. |
| 2407 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2408 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2409 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2410 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2411 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2412 | |
| 2413 | // Making sure SetLocalDescription correctly sets crypto value in |
| 2414 | // SessionDescription object after de-serialization of sdp string. The value |
| 2415 | // will be set as per MediaSessionDescriptionFactory. |
| 2416 | std::string offer_str; |
| 2417 | offer->ToString(&offer_str); |
| 2418 | SessionDescriptionInterface* jsep_offer_str = |
| 2419 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 2420 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 2421 | EXPECT_TRUE(session_->voice_channel()->secure_required()); |
| 2422 | EXPECT_TRUE(session_->video_channel()->secure_required()); |
| 2423 | } |
| 2424 | |
| 2425 | // This test verifies the crypto parameter when security is disabled. |
| 2426 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) { |
mallinath@webrtc.org | 7e809c3 | 2013-09-30 18:59:08 +0000 | [diff] [blame] | 2427 | constraints_.reset(new FakeConstraints()); |
| 2428 | constraints_->AddOptional( |
| 2429 | webrtc::MediaConstraintsInterface::kInternalDisableEncryption, true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2430 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2431 | mediastream_signaling_.SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2432 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2433 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2434 | |
| 2435 | // Making sure SetLocalDescription correctly sets crypto value in |
| 2436 | // SessionDescription object after de-serialization of sdp string. The value |
| 2437 | // will be set as per MediaSessionDescriptionFactory. |
| 2438 | std::string offer_str; |
| 2439 | offer->ToString(&offer_str); |
| 2440 | SessionDescriptionInterface *jsep_offer_str = |
| 2441 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 2442 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 2443 | EXPECT_FALSE(session_->voice_channel()->secure_required()); |
| 2444 | EXPECT_FALSE(session_->video_channel()->secure_required()); |
| 2445 | } |
| 2446 | |
| 2447 | // This test verifies that an answer contains new ufrag and password if an offer |
| 2448 | // with new ufrag and password is received. |
| 2449 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2450 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2451 | cricket::MediaSessionOptions options; |
| 2452 | options.has_audio = true; |
| 2453 | options.has_video = true; |
| 2454 | talk_base::scoped_ptr<JsepSessionDescription> offer( |
| 2455 | CreateRemoteOffer(options)); |
| 2456 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2457 | |
| 2458 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2459 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2460 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2461 | SetLocalDescriptionWithoutError(answer.release()); |
| 2462 | |
| 2463 | // Receive an offer with new ufrag and password. |
| 2464 | options.transport_options.ice_restart = true; |
| 2465 | talk_base::scoped_ptr<JsepSessionDescription> updated_offer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2466 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2467 | SetRemoteDescriptionWithoutError(updated_offer1.release()); |
| 2468 | |
| 2469 | talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2470 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2471 | |
| 2472 | CompareIceUfragAndPassword(updated_answer1->description(), |
| 2473 | session_->local_description()->description(), |
| 2474 | false); |
| 2475 | |
| 2476 | SetLocalDescriptionWithoutError(updated_answer1.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2477 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2478 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2479 | // This test verifies that an answer contains old ufrag and password if an offer |
| 2480 | // with old ufrag and password is received. |
| 2481 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
| 2482 | Init(NULL); |
| 2483 | cricket::MediaSessionOptions options; |
| 2484 | options.has_audio = true; |
| 2485 | options.has_video = true; |
| 2486 | talk_base::scoped_ptr<JsepSessionDescription> offer( |
| 2487 | CreateRemoteOffer(options)); |
| 2488 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2489 | |
| 2490 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2491 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 2492 | CreateAnswer(NULL)); |
| 2493 | SetLocalDescriptionWithoutError(answer.release()); |
| 2494 | |
| 2495 | // Receive an offer without changed ufrag or password. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2496 | options.transport_options.ice_restart = false; |
| 2497 | talk_base::scoped_ptr<JsepSessionDescription> updated_offer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2498 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2499 | SetRemoteDescriptionWithoutError(updated_offer2.release()); |
| 2500 | |
| 2501 | talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2502 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2503 | |
| 2504 | CompareIceUfragAndPassword(updated_answer2->description(), |
| 2505 | session_->local_description()->description(), |
| 2506 | true); |
| 2507 | |
| 2508 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 2509 | } |
| 2510 | |
| 2511 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2512 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2513 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2514 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2515 | const std::string session_id_orig = offer->session_id(); |
| 2516 | const std::string session_version_orig = offer->session_version(); |
| 2517 | SetLocalDescriptionWithoutError(offer); |
| 2518 | |
| 2519 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2520 | video_channel_->set_fail_set_send_codecs(true); |
| 2521 | |
| 2522 | mediastream_signaling_.SendAudioVideoStream2(); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2523 | SessionDescriptionInterface* answer = |
| 2524 | CreateRemoteAnswer(session_->local_description()); |
| 2525 | SetRemoteDescriptionExpectError("ERROR_CONTENT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 2529 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 2530 | // Lets try with only UDP ports. |
| 2531 | allocator_.set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
| 2532 | cricket::PORTALLOCATOR_DISABLE_TCP | |
| 2533 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2534 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 2535 | TestLoopbackCall(); |
| 2536 | } |
| 2537 | |
| 2538 | // Regression-test for a crash which should have been an error. |
| 2539 | TEST_F(WebRtcSessionTest, TestNoStateTransitionPendingError) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2540 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2541 | cricket::MediaSessionOptions options; |
| 2542 | options.has_audio = true; |
| 2543 | options.has_video = true; |
| 2544 | |
| 2545 | session_->SetError(cricket::BaseSession::ERROR_CONTENT); |
| 2546 | SessionDescriptionInterface* offer = CreateRemoteOffer(options); |
| 2547 | SessionDescriptionInterface* answer = |
| 2548 | CreateRemoteAnswer(offer, options); |
| 2549 | SetRemoteDescriptionExpectError(kSessionError, offer); |
| 2550 | SetLocalDescriptionExpectError(kSessionError, answer); |
| 2551 | // Not crashing is our success. |
| 2552 | } |
| 2553 | |
| 2554 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
| 2555 | constraints_.reset(new FakeConstraints()); |
| 2556 | constraints_->AddOptional( |
| 2557 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
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 | |
| 2560 | SetLocalDescriptionWithDataChannel(); |
| 2561 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 2562 | } |
| 2563 | |
| 2564 | TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
| 2565 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2566 | |
| 2567 | constraints_.reset(new FakeConstraints()); |
| 2568 | constraints_->AddOptional( |
| 2569 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
| 2570 | constraints_->AddOptional( |
| 2571 | webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2572 | InitWithDtls(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2573 | |
| 2574 | SetLocalDescriptionWithDataChannel(); |
| 2575 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 2576 | } |
| 2577 | |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 2578 | TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
| 2579 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2580 | |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2581 | constraints_.reset(new FakeConstraints()); |
| 2582 | constraints_->AddOptional( |
| 2583 | webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true); |
| 2584 | InitWithDtls(false); |
| 2585 | |
| 2586 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2587 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2588 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 2589 | } |
| 2590 | |
| 2591 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
| 2592 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2593 | SetFactoryDtlsSrtp(); |
| 2594 | constraints_.reset(new FakeConstraints()); |
| 2595 | constraints_->AddOptional( |
| 2596 | webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true); |
| 2597 | InitWithDtls(false); |
| 2598 | |
| 2599 | // Create remote offer with SCTP. |
| 2600 | cricket::MediaSessionOptions options; |
| 2601 | options.data_channel_type = cricket::DCT_SCTP; |
| 2602 | JsepSessionDescription* offer = |
| 2603 | CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 2604 | SetRemoteDescriptionWithoutError(offer); |
| 2605 | |
| 2606 | // Verifies the answer contains SCTP. |
| 2607 | talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
| 2608 | EXPECT_TRUE(answer != NULL); |
| 2609 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 2610 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2613 | TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
| 2614 | constraints_.reset(new FakeConstraints()); |
| 2615 | constraints_->AddOptional( |
| 2616 | webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2617 | constraints_->AddOptional( |
| 2618 | webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 2619 | InitWithDtls(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2620 | |
| 2621 | SetLocalDescriptionWithDataChannel(); |
| 2622 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 2623 | } |
| 2624 | |
| 2625 | TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
| 2626 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2627 | |
| 2628 | constraints_.reset(new FakeConstraints()); |
| 2629 | constraints_->AddOptional( |
| 2630 | webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2631 | InitWithDtls(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2632 | |
| 2633 | SetLocalDescriptionWithDataChannel(); |
| 2634 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 2635 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2636 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame^] | 2637 | TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
| 2638 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2639 | const int new_send_port = 9998; |
| 2640 | const int new_recv_port = 7775; |
| 2641 | |
| 2642 | constraints_.reset(new FakeConstraints()); |
| 2643 | constraints_->AddOptional( |
| 2644 | webrtc::MediaConstraintsInterface::kEnableSctpDataChannels, true); |
| 2645 | |
| 2646 | InitWithDtls(false); |
| 2647 | SetFactoryDtlsSrtp(); |
| 2648 | |
| 2649 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 2650 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 2651 | // let the session description get parsed. That'll get the proper codecs |
| 2652 | // into the stream. |
| 2653 | cricket::MediaSessionOptions options; |
| 2654 | JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort( |
| 2655 | "stream1", new_send_port, options); |
| 2656 | |
| 2657 | // SetRemoteDescription will take the ownership of the offer. |
| 2658 | SetRemoteDescriptionWithoutError(offer); |
| 2659 | |
| 2660 | SessionDescriptionInterface* answer = ChangeSDPSctpPort( |
| 2661 | new_recv_port, CreateAnswer(NULL)); |
| 2662 | ASSERT_TRUE(answer != NULL); |
| 2663 | |
| 2664 | // Now set the local description, which'll take ownership of the answer. |
| 2665 | SetLocalDescriptionWithoutError(answer); |
| 2666 | |
| 2667 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 2668 | // and pass it all the way down. |
| 2669 | webrtc::DataChannelInit dci; |
| 2670 | dci.reliable = true; |
| 2671 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 2672 | talk_base::scoped_refptr<webrtc::DataChannel> dc = |
| 2673 | session_->CreateDataChannel("datachannel", &dci); |
| 2674 | |
| 2675 | cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0); |
| 2676 | int portnum = -1; |
| 2677 | ASSERT_TRUE(ch != NULL); |
| 2678 | ASSERT_EQ(1UL, ch->send_codecs().size()); |
| 2679 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id); |
| 2680 | EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName, |
| 2681 | ch->send_codecs()[0].name.c_str())); |
| 2682 | EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 2683 | &portnum)); |
| 2684 | EXPECT_EQ(new_send_port, portnum); |
| 2685 | |
| 2686 | ASSERT_EQ(1UL, ch->recv_codecs().size()); |
| 2687 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id); |
| 2688 | EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName, |
| 2689 | ch->recv_codecs()[0].name.c_str())); |
| 2690 | EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 2691 | &portnum)); |
| 2692 | EXPECT_EQ(new_recv_port, portnum); |
| 2693 | } |
| 2694 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2695 | // Verifies that CreateOffer succeeds when CreateOffer is called before async |
| 2696 | // identity generation is finished. |
| 2697 | TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { |
| 2698 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2699 | InitWithDtls(false); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2700 | |
| 2701 | EXPECT_TRUE(session_->waiting_for_identity()); |
| 2702 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2703 | EXPECT_TRUE(offer != NULL); |
| 2704 | } |
| 2705 | |
| 2706 | // Verifies that CreateAnswer succeeds when CreateOffer is called before async |
| 2707 | // identity generation is finished. |
| 2708 | TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { |
| 2709 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2710 | InitWithDtls(false); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2711 | |
| 2712 | cricket::MediaSessionOptions options; |
| 2713 | scoped_ptr<JsepSessionDescription> offer( |
| 2714 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 2715 | ASSERT_TRUE(offer.get() != NULL); |
| 2716 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2717 | |
| 2718 | talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
| 2719 | EXPECT_TRUE(answer != NULL); |
| 2720 | } |
| 2721 | |
| 2722 | // Verifies that CreateOffer succeeds when CreateOffer is called after async |
| 2723 | // identity generation is finished. |
| 2724 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { |
| 2725 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2726 | InitWithDtls(false); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2727 | |
| 2728 | EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); |
| 2729 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2730 | EXPECT_TRUE(offer != NULL); |
| 2731 | } |
| 2732 | |
| 2733 | // Verifies that CreateOffer fails when CreateOffer is called after async |
| 2734 | // identity generation fails. |
| 2735 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { |
| 2736 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2737 | InitWithDtls(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2738 | |
| 2739 | EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); |
| 2740 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2741 | EXPECT_TRUE(offer == NULL); |
| 2742 | } |
| 2743 | |
| 2744 | // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made |
| 2745 | // before async identity generation is finished. |
| 2746 | TEST_F(WebRtcSessionTest, |
| 2747 | TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { |
| 2748 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2749 | VerifyMultipleAsyncCreateDescription( |
| 2750 | true, CreateSessionDescriptionRequest::kOffer); |
| 2751 | } |
| 2752 | |
| 2753 | // Verifies that CreateOffer fails when Multiple CreateOffer calls are made |
| 2754 | // before async identity generation fails. |
| 2755 | TEST_F(WebRtcSessionTest, |
| 2756 | TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) { |
| 2757 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2758 | VerifyMultipleAsyncCreateDescription( |
| 2759 | false, CreateSessionDescriptionRequest::kOffer); |
| 2760 | } |
| 2761 | |
| 2762 | // Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made |
| 2763 | // before async identity generation is finished. |
| 2764 | TEST_F(WebRtcSessionTest, |
| 2765 | TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) { |
| 2766 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2767 | VerifyMultipleAsyncCreateDescription( |
| 2768 | true, CreateSessionDescriptionRequest::kAnswer); |
| 2769 | } |
| 2770 | |
| 2771 | // Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made |
| 2772 | // before async identity generation fails. |
| 2773 | TEST_F(WebRtcSessionTest, |
| 2774 | TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) { |
| 2775 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2776 | VerifyMultipleAsyncCreateDescription( |
| 2777 | false, CreateSessionDescriptionRequest::kAnswer); |
| 2778 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2779 | |
| 2780 | // Verifies that setRemoteDescription fails when DTLS is disabled and the remote |
| 2781 | // offer has no SDES crypto but only DTLS fingerprint. |
| 2782 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { |
| 2783 | // Init without DTLS. |
| 2784 | Init(NULL); |
| 2785 | // Create a remote offer with secured transport disabled. |
| 2786 | cricket::MediaSessionOptions options; |
| 2787 | JsepSessionDescription* offer(CreateRemoteOffer( |
| 2788 | options, cricket::SEC_DISABLED)); |
| 2789 | // Adds a DTLS fingerprint to the remote offer. |
| 2790 | cricket::SessionDescription* sdp = offer->description(); |
| 2791 | TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 2792 | ASSERT_TRUE(audio != NULL); |
| 2793 | ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); |
| 2794 | audio->description.identity_fingerprint.reset( |
| 2795 | talk_base::SSLFingerprint::CreateFromRfc4572( |
| 2796 | talk_base::DIGEST_SHA_256, kFakeDtlsFingerprint)); |
| 2797 | SetRemoteDescriptionExpectError(kSdpWithoutSdesAndDtlsDisabled, |
| 2798 | offer); |
| 2799 | } |
| 2800 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2801 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 2802 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 2803 | // called more than once without returning to IceGatheringGathering. |