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