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 | |
| 1424 | candidate.set_component(2); |
| 1425 | JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); |
| 1426 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); |
| 1427 | ASSERT_EQ(3u, candidates->count()); |
| 1428 | |
| 1429 | JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); |
| 1430 | EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); |
| 1431 | } |
| 1432 | |
| 1433 | // Test that a remote candidate is added to the remote session description and |
| 1434 | // that it is retained if the remote session description is changed. |
| 1435 | TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1436 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1437 | cricket::Candidate candidate1; |
| 1438 | candidate1.set_component(1); |
| 1439 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 1440 | candidate1); |
| 1441 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1442 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1443 | |
| 1444 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1445 | const SessionDescriptionInterface* remote_desc = |
| 1446 | session_->remote_description(); |
| 1447 | ASSERT_TRUE(remote_desc != NULL); |
| 1448 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1449 | const IceCandidateCollection* candidates = |
| 1450 | remote_desc->candidates(kMediaContentIndex0); |
| 1451 | ASSERT_EQ(1u, candidates->count()); |
| 1452 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1453 | |
| 1454 | // Update the RemoteSessionDescription with a new session description and |
| 1455 | // a candidate and check that the new remote session description contains both |
| 1456 | // candidates. |
| 1457 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 1458 | cricket::Candidate candidate2; |
| 1459 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 1460 | candidate2); |
| 1461 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 1462 | SetRemoteDescriptionWithoutError(offer); |
| 1463 | |
| 1464 | remote_desc = session_->remote_description(); |
| 1465 | ASSERT_TRUE(remote_desc != NULL); |
| 1466 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1467 | candidates = remote_desc->candidates(kMediaContentIndex0); |
| 1468 | ASSERT_EQ(2u, candidates->count()); |
| 1469 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1470 | // Username and password have be updated with the TransportInfo of the |
| 1471 | // SessionDescription, won't be equal to the original one. |
| 1472 | candidate2.set_username(candidates->at(0)->candidate().username()); |
| 1473 | candidate2.set_password(candidates->at(0)->candidate().password()); |
| 1474 | EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate())); |
| 1475 | EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index()); |
| 1476 | // No need to verify the username and password. |
| 1477 | candidate1.set_username(candidates->at(1)->candidate().username()); |
| 1478 | candidate1.set_password(candidates->at(1)->candidate().password()); |
| 1479 | EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); |
| 1480 | |
| 1481 | // Test that the candidate is ignored if we can add the same candidate again. |
| 1482 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 1483 | } |
| 1484 | |
| 1485 | // Test that local candidates are added to the local session description and |
| 1486 | // that they are retained if the local session description is changed. |
| 1487 | TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1488 | AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1489 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1490 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1491 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1492 | |
| 1493 | const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 1494 | const IceCandidateCollection* candidates = |
| 1495 | local_desc->candidates(kMediaContentIndex0); |
| 1496 | ASSERT_TRUE(candidates != NULL); |
| 1497 | EXPECT_EQ(0u, candidates->count()); |
| 1498 | |
| 1499 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1500 | |
| 1501 | local_desc = session_->local_description(); |
| 1502 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 1503 | ASSERT_TRUE(candidates != NULL); |
| 1504 | EXPECT_LT(0u, candidates->count()); |
| 1505 | candidates = local_desc->candidates(1); |
| 1506 | ASSERT_TRUE(candidates != NULL); |
| 1507 | EXPECT_LT(0u, candidates->count()); |
| 1508 | |
| 1509 | // Update the session descriptions. |
| 1510 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1511 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1512 | |
| 1513 | local_desc = session_->local_description(); |
| 1514 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 1515 | ASSERT_TRUE(candidates != NULL); |
| 1516 | EXPECT_LT(0u, candidates->count()); |
| 1517 | candidates = local_desc->candidates(1); |
| 1518 | ASSERT_TRUE(candidates != NULL); |
| 1519 | EXPECT_LT(0u, candidates->count()); |
| 1520 | } |
| 1521 | |
| 1522 | // Test that we can set a remote session description with remote candidates. |
| 1523 | TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1524 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1525 | |
| 1526 | cricket::Candidate candidate1; |
| 1527 | candidate1.set_component(1); |
| 1528 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 1529 | candidate1); |
| 1530 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1531 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1532 | |
| 1533 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 1534 | SetRemoteDescriptionWithoutError(offer); |
| 1535 | |
| 1536 | const SessionDescriptionInterface* remote_desc = |
| 1537 | session_->remote_description(); |
| 1538 | ASSERT_TRUE(remote_desc != NULL); |
| 1539 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 1540 | const IceCandidateCollection* candidates = |
| 1541 | remote_desc->candidates(kMediaContentIndex0); |
| 1542 | ASSERT_EQ(1u, candidates->count()); |
| 1543 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 1544 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1545 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1546 | SetLocalDescriptionWithoutError(answer); |
| 1547 | } |
| 1548 | |
| 1549 | // Test that offers and answers contains ice candidates when Ice candidates have |
| 1550 | // been gathered. |
| 1551 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1552 | AddInterface(talk_base::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1553 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1554 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1555 | // Ice is started but candidates are not provided until SetLocalDescription |
| 1556 | // is called. |
| 1557 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 1558 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 1559 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1560 | // Wait until at least one local candidate has been collected. |
| 1561 | EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(), |
| 1562 | kIceCandidatesTimeout); |
| 1563 | EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(), |
| 1564 | kIceCandidatesTimeout); |
| 1565 | |
| 1566 | talk_base::scoped_ptr<SessionDescriptionInterface> local_offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1567 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1568 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL); |
| 1569 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count()); |
| 1570 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL); |
| 1571 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count()); |
| 1572 | |
| 1573 | SessionDescriptionInterface* remote_offer(CreateRemoteOffer()); |
| 1574 | SetRemoteDescriptionWithoutError(remote_offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1575 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1576 | ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL); |
| 1577 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count()); |
| 1578 | ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL); |
| 1579 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count()); |
| 1580 | SetLocalDescriptionWithoutError(answer); |
| 1581 | } |
| 1582 | |
| 1583 | // Verifies TransportProxy and media channels are created with content names |
| 1584 | // present in the SessionDescription. |
| 1585 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1586 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1587 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1588 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1589 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1590 | |
| 1591 | // CreateOffer creates session description with the content names "audio" and |
| 1592 | // "video". Goal is to modify these content names and verify transport channel |
| 1593 | // proxy in the BaseSession, as proxies are created with the content names |
| 1594 | // present in SDP. |
| 1595 | std::string sdp; |
| 1596 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 1597 | const std::string kAudioMid = "a=mid:audio"; |
| 1598 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 1599 | const std::string kVideoMid = "a=mid:video"; |
| 1600 | const std::string kVideoMidReplaceStr = "a=mid:video_content_name"; |
| 1601 | |
| 1602 | // Replacing |audio| with |audio_content_name|. |
| 1603 | talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
| 1604 | kAudioMidReplaceStr.c_str(), |
| 1605 | kAudioMidReplaceStr.length(), |
| 1606 | &sdp); |
| 1607 | // Replacing |video| with |video_content_name|. |
| 1608 | talk_base::replace_substrs(kVideoMid.c_str(), kVideoMid.length(), |
| 1609 | kVideoMidReplaceStr.c_str(), |
| 1610 | kVideoMidReplaceStr.length(), |
| 1611 | &sdp); |
| 1612 | |
| 1613 | SessionDescriptionInterface* modified_offer = |
| 1614 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 1615 | |
| 1616 | SetRemoteDescriptionWithoutError(modified_offer); |
| 1617 | |
| 1618 | SessionDescriptionInterface* answer = |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1619 | CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | SetLocalDescriptionWithoutError(answer); |
| 1621 | |
| 1622 | EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL); |
| 1623 | EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL); |
| 1624 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 1625 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 1626 | } |
| 1627 | |
| 1628 | // Test that an offer contains the correct media content descriptions based on |
| 1629 | // the send streams when no constraints have been set. |
| 1630 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1631 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1632 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1633 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1634 | ASSERT_TRUE(offer != NULL); |
| 1635 | const cricket::ContentInfo* content = |
| 1636 | cricket::GetFirstAudioContent(offer->description()); |
| 1637 | EXPECT_TRUE(content != NULL); |
| 1638 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1639 | EXPECT_TRUE(content == NULL); |
| 1640 | } |
| 1641 | |
| 1642 | // Test that an offer contains the correct media content descriptions based on |
| 1643 | // the send streams when no constraints have been set. |
| 1644 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1645 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1646 | // Test Audio only offer. |
| 1647 | mediastream_signaling_.UseOptionsAudioOnly(); |
| 1648 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1649 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1650 | const cricket::ContentInfo* content = |
| 1651 | cricket::GetFirstAudioContent(offer->description()); |
| 1652 | EXPECT_TRUE(content != NULL); |
| 1653 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1654 | EXPECT_TRUE(content == NULL); |
| 1655 | |
| 1656 | // Test Audio / Video offer. |
| 1657 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1658 | offer.reset(CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1659 | content = cricket::GetFirstAudioContent(offer->description()); |
| 1660 | EXPECT_TRUE(content != NULL); |
| 1661 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1662 | EXPECT_TRUE(content != NULL); |
| 1663 | } |
| 1664 | |
| 1665 | // Test that an offer contains no media content descriptions if |
| 1666 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 1667 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1668 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1669 | webrtc::FakeConstraints constraints_no_receive; |
| 1670 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 1671 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 1672 | |
| 1673 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1674 | CreateOffer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1675 | ASSERT_TRUE(offer != NULL); |
| 1676 | const cricket::ContentInfo* content = |
| 1677 | cricket::GetFirstAudioContent(offer->description()); |
| 1678 | EXPECT_TRUE(content == NULL); |
| 1679 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1680 | EXPECT_TRUE(content == NULL); |
| 1681 | } |
| 1682 | |
| 1683 | // Test that an offer contains only audio media content descriptions if |
| 1684 | // kOfferToReceiveAudio constraints are set to true. |
| 1685 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1686 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1687 | webrtc::FakeConstraints constraints_audio_only; |
| 1688 | constraints_audio_only.SetMandatoryReceiveAudio(true); |
| 1689 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1690 | CreateOffer(&constraints_audio_only)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1691 | |
| 1692 | const cricket::ContentInfo* content = |
| 1693 | cricket::GetFirstAudioContent(offer->description()); |
| 1694 | EXPECT_TRUE(content != NULL); |
| 1695 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1696 | EXPECT_TRUE(content == NULL); |
| 1697 | } |
| 1698 | |
| 1699 | // Test that an offer contains audio and video media content descriptions if |
| 1700 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 1701 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1702 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1703 | // Test Audio / Video offer. |
| 1704 | webrtc::FakeConstraints constraints_audio_video; |
| 1705 | constraints_audio_video.SetMandatoryReceiveAudio(true); |
| 1706 | constraints_audio_video.SetMandatoryReceiveVideo(true); |
| 1707 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1708 | CreateOffer(&constraints_audio_video)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1709 | const cricket::ContentInfo* content = |
| 1710 | cricket::GetFirstAudioContent(offer->description()); |
| 1711 | |
| 1712 | EXPECT_TRUE(content != NULL); |
| 1713 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1714 | EXPECT_TRUE(content != NULL); |
| 1715 | |
| 1716 | // TODO(perkj): Should the direction be set to SEND_ONLY if |
| 1717 | // The constraints is set to not receive audio or video but a track is added? |
| 1718 | } |
| 1719 | |
| 1720 | // Test that an answer can not be created if the last remote description is not |
| 1721 | // an offer. |
| 1722 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1723 | Init(NULL); |
| 1724 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1725 | SetLocalDescriptionWithoutError(offer); |
| 1726 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 1727 | SetRemoteDescriptionWithoutError(answer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1728 | EXPECT_TRUE(CreateAnswer(NULL) == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | // Test that an answer contains the correct media content descriptions when no |
| 1732 | // constraints have been set. |
| 1733 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1734 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1735 | // Create a remote offer with audio and video content. |
| 1736 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1737 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1738 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1739 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1740 | const cricket::ContentInfo* content = |
| 1741 | cricket::GetFirstAudioContent(answer->description()); |
| 1742 | ASSERT_TRUE(content != NULL); |
| 1743 | EXPECT_FALSE(content->rejected); |
| 1744 | |
| 1745 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1746 | ASSERT_TRUE(content != NULL); |
| 1747 | EXPECT_FALSE(content->rejected); |
| 1748 | } |
| 1749 | |
| 1750 | // Test that an answer contains the correct media content descriptions when no |
| 1751 | // constraints have been set and the offer only contain audio. |
| 1752 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1753 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1754 | // Create a remote offer with audio only. |
| 1755 | cricket::MediaSessionOptions options; |
| 1756 | options.has_audio = true; |
| 1757 | options.has_video = false; |
| 1758 | talk_base::scoped_ptr<JsepSessionDescription> offer( |
| 1759 | CreateRemoteOffer(options)); |
| 1760 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 1761 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 1762 | |
| 1763 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1764 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1765 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1766 | const cricket::ContentInfo* content = |
| 1767 | cricket::GetFirstAudioContent(answer->description()); |
| 1768 | ASSERT_TRUE(content != NULL); |
| 1769 | EXPECT_FALSE(content->rejected); |
| 1770 | |
| 1771 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 1772 | } |
| 1773 | |
| 1774 | // Test that an answer contains the correct media content descriptions when no |
| 1775 | // constraints have been set. |
| 1776 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1777 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1778 | // Create a remote offer with audio and video content. |
| 1779 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1780 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1781 | // Test with a stream with tracks. |
| 1782 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1783 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1784 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1785 | const cricket::ContentInfo* content = |
| 1786 | cricket::GetFirstAudioContent(answer->description()); |
| 1787 | ASSERT_TRUE(content != NULL); |
| 1788 | EXPECT_FALSE(content->rejected); |
| 1789 | |
| 1790 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1791 | ASSERT_TRUE(content != NULL); |
| 1792 | EXPECT_FALSE(content->rejected); |
| 1793 | } |
| 1794 | |
| 1795 | // Test that an answer contains the correct media content descriptions when |
| 1796 | // constraints have been set but no stream is sent. |
| 1797 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1798 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1799 | // Create a remote offer with audio and video content. |
| 1800 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1801 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1802 | |
| 1803 | webrtc::FakeConstraints constraints_no_receive; |
| 1804 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 1805 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 1806 | |
| 1807 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1808 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1809 | const cricket::ContentInfo* content = |
| 1810 | cricket::GetFirstAudioContent(answer->description()); |
| 1811 | ASSERT_TRUE(content != NULL); |
| 1812 | EXPECT_TRUE(content->rejected); |
| 1813 | |
| 1814 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1815 | ASSERT_TRUE(content != NULL); |
| 1816 | EXPECT_TRUE(content->rejected); |
| 1817 | } |
| 1818 | |
| 1819 | // Test that an answer contains the correct media content descriptions when |
| 1820 | // constraints have been set and streams are sent. |
| 1821 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1822 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1823 | // Create a remote offer with audio and video content. |
| 1824 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1825 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1826 | |
| 1827 | webrtc::FakeConstraints constraints_no_receive; |
| 1828 | constraints_no_receive.SetMandatoryReceiveAudio(false); |
| 1829 | constraints_no_receive.SetMandatoryReceiveVideo(false); |
| 1830 | |
| 1831 | // Test with a stream with tracks. |
| 1832 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1833 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1834 | CreateAnswer(&constraints_no_receive)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1835 | |
| 1836 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1837 | const cricket::ContentInfo* content = |
| 1838 | cricket::GetFirstAudioContent(answer->description()); |
| 1839 | ASSERT_TRUE(content != NULL); |
| 1840 | EXPECT_FALSE(content->rejected); |
| 1841 | |
| 1842 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1843 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1844 | ASSERT_TRUE(content != NULL); |
| 1845 | EXPECT_FALSE(content->rejected); |
| 1846 | } |
| 1847 | |
| 1848 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 1849 | AddCNCodecs(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1850 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1851 | webrtc::FakeConstraints constraints; |
| 1852 | constraints.SetOptionalVAD(false); |
| 1853 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1854 | CreateOffer(&constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1855 | const cricket::ContentInfo* content = |
| 1856 | cricket::GetFirstAudioContent(offer->description()); |
| 1857 | EXPECT_TRUE(content != NULL); |
| 1858 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1859 | } |
| 1860 | |
| 1861 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 1862 | AddCNCodecs(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1863 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1864 | // Create a remote offer with audio and video content. |
| 1865 | talk_base::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
| 1866 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1867 | |
| 1868 | webrtc::FakeConstraints constraints; |
| 1869 | constraints.SetOptionalVAD(false); |
| 1870 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1871 | CreateAnswer(&constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1872 | const cricket::ContentInfo* content = |
| 1873 | cricket::GetFirstAudioContent(answer->description()); |
| 1874 | ASSERT_TRUE(content != NULL); |
| 1875 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1876 | } |
| 1877 | |
| 1878 | // This test verifies the call setup when remote answer with audio only and |
| 1879 | // later updates with video. |
| 1880 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1881 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1882 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 1883 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 1884 | |
| 1885 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1886 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1887 | |
| 1888 | cricket::MediaSessionOptions options; |
| 1889 | options.has_video = false; |
| 1890 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 1891 | |
| 1892 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1893 | // and answer; |
| 1894 | SetLocalDescriptionWithoutError(offer); |
| 1895 | SetRemoteDescriptionWithoutError(answer); |
| 1896 | |
| 1897 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1898 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1899 | |
| 1900 | ASSERT_TRUE(video_channel_ == NULL); |
| 1901 | |
| 1902 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 1903 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1904 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 1905 | |
| 1906 | // Let the remote end update the session descriptions, with Audio and Video. |
| 1907 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1908 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1909 | |
| 1910 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1911 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1912 | |
| 1913 | ASSERT_TRUE(video_channel_ != NULL); |
| 1914 | ASSERT_TRUE(voice_channel_ != NULL); |
| 1915 | |
| 1916 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1917 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1918 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 1919 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 1920 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1921 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1922 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1923 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1924 | |
| 1925 | // Change session back to audio only. |
| 1926 | mediastream_signaling_.UseOptionsAudioOnly(); |
| 1927 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1928 | |
| 1929 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 1930 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1931 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1932 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1933 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1934 | } |
| 1935 | |
| 1936 | // This test verifies the call setup when remote answer with video only and |
| 1937 | // later updates with audio. |
| 1938 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1939 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1940 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 1941 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 1942 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1943 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1944 | |
| 1945 | cricket::MediaSessionOptions options; |
| 1946 | options.has_audio = false; |
| 1947 | options.has_video = true; |
| 1948 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 1949 | offer, options, cricket::SEC_ENABLED); |
| 1950 | |
| 1951 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1952 | // and answer. |
| 1953 | SetLocalDescriptionWithoutError(offer); |
| 1954 | SetRemoteDescriptionWithoutError(answer); |
| 1955 | |
| 1956 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1957 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1958 | |
| 1959 | ASSERT_TRUE(voice_channel_ == NULL); |
| 1960 | ASSERT_TRUE(video_channel_ != NULL); |
| 1961 | |
| 1962 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 1963 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1964 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 1965 | |
| 1966 | // Update the session descriptions, with Audio and Video. |
| 1967 | mediastream_signaling_.SendAudioVideoStream2(); |
| 1968 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1969 | |
| 1970 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1971 | ASSERT_TRUE(voice_channel_ != NULL); |
| 1972 | |
| 1973 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1974 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1975 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1976 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1977 | |
| 1978 | // Change session back to video only. |
| 1979 | mediastream_signaling_.UseOptionsVideoOnly(); |
| 1980 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1981 | |
| 1982 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1983 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1984 | |
| 1985 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1986 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 1987 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1988 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 1989 | } |
| 1990 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1991 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1992 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1993 | mediastream_signaling_.SendAudioVideoStream1(); |
| 1994 | scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1995 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1996 | VerifyCryptoParams(offer->description()); |
| 1997 | SetRemoteDescriptionWithoutError(offer.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1998 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1999 | VerifyCryptoParams(answer->description()); |
| 2000 | } |
| 2001 | |
| 2002 | TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2003 | options_.disable_encryption = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2004 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2005 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2006 | scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2007 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2008 | VerifyNoCryptoParams(offer->description(), false); |
| 2009 | } |
| 2010 | |
| 2011 | TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2012 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2013 | VerifyAnswerFromNonCryptoOffer(); |
| 2014 | } |
| 2015 | |
| 2016 | TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2017 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2018 | VerifyAnswerFromCryptoOffer(); |
| 2019 | } |
| 2020 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2021 | // This test verifies that setLocalDescription fails if |
| 2022 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2023 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) { |
| 2024 | Init(NULL); |
| 2025 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2026 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2027 | std::string sdp; |
| 2028 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2029 | SessionDescriptionInterface* modified_offer = |
| 2030 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2031 | SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | // This test verifies that setRemoteDescription fails if |
| 2035 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2036 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) { |
| 2037 | Init(NULL); |
| 2038 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 2039 | std::string sdp; |
| 2040 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2041 | SessionDescriptionInterface* modified_offer = |
| 2042 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2043 | SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2046 | TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) { |
| 2047 | // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in |
| 2048 | // local description is removed by the application, BUNDLE flag should be |
| 2049 | // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2050 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2051 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2052 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2053 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2054 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2055 | cricket::SessionDescription* offer_copy = |
| 2056 | offer->description()->Copy(); |
| 2057 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2058 | JsepSessionDescription* modified_offer = |
| 2059 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2060 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 2061 | |
| 2062 | SetLocalDescriptionWithoutError(modified_offer); |
| 2063 | EXPECT_FALSE(allocator_.flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2064 | } |
| 2065 | |
| 2066 | TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2067 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2068 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2069 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2070 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2071 | FakeConstraints constraints; |
| 2072 | constraints.SetMandatoryUseRtpMux(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2073 | SessionDescriptionInterface* offer = CreateOffer(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | SetLocalDescriptionWithoutError(offer); |
| 2075 | mediastream_signaling_.SendAudioVideoStream2(); |
| 2076 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 2077 | CreateRemoteAnswer(session_->local_description())); |
| 2078 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2079 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2080 | JsepSessionDescription* modified_answer = |
| 2081 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2082 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2083 | SetRemoteDescriptionWithoutError(modified_answer); |
| 2084 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2085 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2086 | |
| 2087 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2088 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2089 | |
| 2090 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2091 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 2092 | |
| 2093 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2094 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 2095 | |
| 2096 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2097 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 2098 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2099 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 2100 | } |
| 2101 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2102 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 2103 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 2104 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2105 | WebRtcSessionTest::Init(NULL); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2106 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2107 | EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE & allocator_.flags()) == |
| 2108 | cricket::PORTALLOCATOR_ENABLE_BUNDLE); |
| 2109 | FakeConstraints constraints; |
| 2110 | constraints.SetMandatoryUseRtpMux(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2111 | SessionDescriptionInterface* offer = CreateOffer(&constraints); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2112 | std::string offer_str; |
| 2113 | offer->ToString(&offer_str); |
| 2114 | // Disable rtcp-mux |
| 2115 | const std::string rtcp_mux = "rtcp-mux"; |
| 2116 | const std::string xrtcp_mux = "xrtcp-mux"; |
| 2117 | talk_base::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
| 2118 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 2119 | &offer_str); |
| 2120 | JsepSessionDescription *local_offer = |
| 2121 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2122 | EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2123 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2124 | JsepSessionDescription *remote_offer = |
| 2125 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2126 | EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2127 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2128 | // Trying unmodified SDP. |
| 2129 | SetLocalDescriptionWithoutError(offer); |
| 2130 | } |
| 2131 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2132 | TEST_F(WebRtcSessionTest, SetAudioPlayout) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2133 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2134 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2135 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2136 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2137 | ASSERT_TRUE(channel != NULL); |
| 2138 | ASSERT_EQ(1u, channel->recv_streams().size()); |
| 2139 | uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
| 2140 | double left_vol, right_vol; |
| 2141 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2142 | EXPECT_EQ(1, left_vol); |
| 2143 | EXPECT_EQ(1, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2144 | talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
| 2145 | session_->SetAudioPlayout(receive_ssrc, false, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2146 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2147 | EXPECT_EQ(0, left_vol); |
| 2148 | EXPECT_EQ(0, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2149 | EXPECT_EQ(0, renderer->channel_id()); |
| 2150 | session_->SetAudioPlayout(receive_ssrc, true, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2151 | EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); |
| 2152 | EXPECT_EQ(1, left_vol); |
| 2153 | EXPECT_EQ(1, right_vol); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2154 | EXPECT_EQ(-1, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | TEST_F(WebRtcSessionTest, SetAudioSend) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2158 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2159 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2160 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2161 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2162 | ASSERT_TRUE(channel != NULL); |
| 2163 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2164 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2165 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2166 | |
| 2167 | cricket::AudioOptions options; |
| 2168 | options.echo_cancellation.Set(true); |
| 2169 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2170 | talk_base::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); |
| 2171 | session_->SetAudioSend(send_ssrc, false, options, renderer.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2172 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 2173 | EXPECT_FALSE(channel->options().echo_cancellation.IsSet()); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2174 | EXPECT_EQ(0, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2175 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2176 | session_->SetAudioSend(send_ssrc, true, options, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2177 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2178 | bool value; |
| 2179 | EXPECT_TRUE(channel->options().echo_cancellation.Get(&value)); |
| 2180 | EXPECT_TRUE(value); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2181 | EXPECT_EQ(-1, renderer->channel_id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | TEST_F(WebRtcSessionTest, SetVideoPlayout) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2185 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2186 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2187 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2188 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 2189 | ASSERT_TRUE(channel != NULL); |
| 2190 | ASSERT_LT(0u, channel->renderers().size()); |
| 2191 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 2192 | ASSERT_EQ(1u, channel->recv_streams().size()); |
| 2193 | uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
| 2194 | cricket::FakeVideoRenderer renderer; |
| 2195 | session_->SetVideoPlayout(receive_ssrc, true, &renderer); |
| 2196 | EXPECT_TRUE(channel->renderers().begin()->second == &renderer); |
| 2197 | session_->SetVideoPlayout(receive_ssrc, false, &renderer); |
| 2198 | EXPECT_TRUE(channel->renderers().begin()->second == NULL); |
| 2199 | } |
| 2200 | |
| 2201 | TEST_F(WebRtcSessionTest, SetVideoSend) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2202 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2203 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2204 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2205 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 2206 | ASSERT_TRUE(channel != NULL); |
| 2207 | ASSERT_EQ(1u, channel->send_streams().size()); |
| 2208 | uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2209 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2210 | cricket::VideoOptions* options = NULL; |
| 2211 | session_->SetVideoSend(send_ssrc, false, options); |
| 2212 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 2213 | session_->SetVideoSend(send_ssrc, true, options); |
| 2214 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 2215 | } |
| 2216 | |
| 2217 | TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { |
| 2218 | TestCanInsertDtmf(false); |
| 2219 | } |
| 2220 | |
| 2221 | TEST_F(WebRtcSessionTest, CanInsertDtmf) { |
| 2222 | TestCanInsertDtmf(true); |
| 2223 | } |
| 2224 | |
| 2225 | TEST_F(WebRtcSessionTest, InsertDtmf) { |
| 2226 | // Setup |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2227 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2228 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2229 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2230 | FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 2231 | EXPECT_EQ(0U, channel->dtmf_info_queue().size()); |
| 2232 | |
| 2233 | // Insert DTMF |
| 2234 | const int expected_flags = DF_SEND; |
| 2235 | const int expected_duration = 90; |
| 2236 | session_->InsertDtmf(kAudioTrack1, 0, expected_duration); |
| 2237 | session_->InsertDtmf(kAudioTrack1, 1, expected_duration); |
| 2238 | session_->InsertDtmf(kAudioTrack1, 2, expected_duration); |
| 2239 | |
| 2240 | // Verify |
| 2241 | ASSERT_EQ(3U, channel->dtmf_info_queue().size()); |
| 2242 | const uint32 send_ssrc = channel->send_streams()[0].first_ssrc(); |
| 2243 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0, |
| 2244 | expected_duration, expected_flags)); |
| 2245 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1, |
| 2246 | expected_duration, expected_flags)); |
| 2247 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2, |
| 2248 | expected_duration, expected_flags)); |
| 2249 | } |
| 2250 | |
| 2251 | // This test verifies the |initiator| flag when session initiates the call. |
| 2252 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2253 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2254 | EXPECT_FALSE(session_->initiator()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2255 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2256 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2257 | SetLocalDescriptionWithoutError(offer); |
| 2258 | EXPECT_TRUE(session_->initiator()); |
| 2259 | SetRemoteDescriptionWithoutError(answer); |
| 2260 | EXPECT_TRUE(session_->initiator()); |
| 2261 | } |
| 2262 | |
| 2263 | // This test verifies the |initiator| flag when session receives the call. |
| 2264 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2265 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2266 | EXPECT_FALSE(session_->initiator()); |
| 2267 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2268 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2269 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2270 | |
| 2271 | EXPECT_FALSE(session_->initiator()); |
| 2272 | SetLocalDescriptionWithoutError(answer); |
| 2273 | EXPECT_FALSE(session_->initiator()); |
| 2274 | } |
| 2275 | |
| 2276 | // This test verifies the ice protocol type at initiator of the call |
| 2277 | // if |a=ice-options:google-ice| is present in answer. |
| 2278 | TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2279 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2280 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2281 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 2282 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2283 | CreateRemoteAnswer(offer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2284 | SetLocalDescriptionWithoutError(offer); |
| 2285 | std::string sdp; |
| 2286 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2287 | // Adding ice-options to the session level. |
| 2288 | InjectAfter("t=0 0\r\n", |
| 2289 | "a=ice-options:google-ice\r\n", |
| 2290 | &sdp); |
| 2291 | SessionDescriptionInterface* answer_with_gice = |
| 2292 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2293 | SetRemoteDescriptionWithoutError(answer_with_gice); |
| 2294 | VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE); |
| 2295 | VerifyTransportType("video", cricket::ICEPROTO_GOOGLE); |
| 2296 | } |
| 2297 | |
| 2298 | // This test verifies the ice protocol type at initiator of the call |
| 2299 | // if ICE RFC5245 is supported in answer. |
| 2300 | TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2301 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2302 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2303 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2304 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2305 | SetLocalDescriptionWithoutError(offer); |
| 2306 | |
| 2307 | SetRemoteDescriptionWithoutError(answer); |
| 2308 | VerifyTransportType("audio", cricket::ICEPROTO_RFC5245); |
| 2309 | VerifyTransportType("video", cricket::ICEPROTO_RFC5245); |
| 2310 | } |
| 2311 | |
| 2312 | // This test verifies the ice protocol type at receiver side of the call if |
| 2313 | // receiver decides to use google-ice. |
| 2314 | TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2315 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2316 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2317 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2318 | SetRemoteDescriptionWithoutError(offer); |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 2319 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2320 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2321 | std::string sdp; |
| 2322 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2323 | // Adding ice-options to the session level. |
| 2324 | InjectAfter("t=0 0\r\n", |
| 2325 | "a=ice-options:google-ice\r\n", |
| 2326 | &sdp); |
| 2327 | SessionDescriptionInterface* answer_with_gice = |
| 2328 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 2329 | SetLocalDescriptionWithoutError(answer_with_gice); |
| 2330 | VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE); |
| 2331 | VerifyTransportType("video", cricket::ICEPROTO_GOOGLE); |
| 2332 | } |
| 2333 | |
| 2334 | // This test verifies the ice protocol type at receiver side of the call if |
| 2335 | // receiver decides to use ice RFC 5245. |
| 2336 | TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2337 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2338 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2339 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2340 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2341 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2342 | SetLocalDescriptionWithoutError(answer); |
| 2343 | VerifyTransportType("audio", cricket::ICEPROTO_RFC5245); |
| 2344 | VerifyTransportType("video", cricket::ICEPROTO_RFC5245); |
| 2345 | } |
| 2346 | |
| 2347 | // This test verifies the session state when ICE RFC5245 in offer and |
| 2348 | // ICE google-ice in answer. |
| 2349 | TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2350 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2351 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2352 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2353 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2354 | std::string offer_str; |
| 2355 | offer->ToString(&offer_str); |
| 2356 | // Disable google-ice |
| 2357 | const std::string gice_option = "google-ice"; |
| 2358 | const std::string xgoogle_xice = "xgoogle-xice"; |
| 2359 | talk_base::replace_substrs(gice_option.c_str(), gice_option.length(), |
| 2360 | xgoogle_xice.c_str(), xgoogle_xice.length(), |
| 2361 | &offer_str); |
| 2362 | JsepSessionDescription *ice_only_offer = |
| 2363 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2364 | EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL)); |
| 2365 | SetLocalDescriptionWithoutError(ice_only_offer); |
| 2366 | std::string original_offer_sdp; |
| 2367 | EXPECT_TRUE(offer->ToString(&original_offer_sdp)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2368 | SessionDescriptionInterface* pranswer_with_gice = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2369 | CreateSessionDescription(JsepSessionDescription::kPrAnswer, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2370 | original_offer_sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2371 | SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed, |
| 2372 | pranswer_with_gice); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2373 | SessionDescriptionInterface* answer_with_gice = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2374 | CreateSessionDescription(JsepSessionDescription::kAnswer, |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2375 | original_offer_sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2376 | SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, |
| 2377 | answer_with_gice); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 2381 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2382 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2383 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2384 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2385 | SetLocalDescriptionWithoutError(offer); |
| 2386 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 2387 | CreateRemoteAnswer(session_->local_description())); |
| 2388 | |
| 2389 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2390 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2391 | JsepSessionDescription* modified_answer = |
| 2392 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2393 | |
| 2394 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2395 | answer->session_id(), |
| 2396 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2397 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2398 | |
| 2399 | // Modifying content names. |
| 2400 | std::string sdp; |
| 2401 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2402 | const std::string kAudioMid = "a=mid:audio"; |
| 2403 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 2404 | |
| 2405 | // Replacing |audio| with |audio_content_name|. |
| 2406 | talk_base::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
| 2407 | kAudioMidReplaceStr.c_str(), |
| 2408 | kAudioMidReplaceStr.length(), |
| 2409 | &sdp); |
| 2410 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2411 | SessionDescriptionInterface* modified_answer1 = |
| 2412 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2413 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2414 | |
| 2415 | SetRemoteDescriptionWithoutError(answer.release()); |
| 2416 | } |
| 2417 | |
| 2418 | // Verifying remote offer and local answer have matching m-lines as per |
| 2419 | // RFC 3264. |
| 2420 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2421 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2422 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2423 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2424 | SetRemoteDescriptionWithoutError(offer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2425 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2426 | |
| 2427 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2428 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2429 | JsepSessionDescription* modified_answer = |
| 2430 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2431 | |
| 2432 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2433 | answer->session_id(), |
| 2434 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2435 | SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2436 | SetLocalDescriptionWithoutError(answer); |
| 2437 | } |
| 2438 | |
| 2439 | // This test verifies that WebRtcSession does not start candidate allocation |
| 2440 | // before SetLocalDescription is called. |
| 2441 | TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2442 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2443 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2444 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2445 | cricket::Candidate candidate; |
| 2446 | candidate.set_component(1); |
| 2447 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2448 | candidate); |
| 2449 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2450 | cricket::Candidate candidate1; |
| 2451 | candidate1.set_component(1); |
| 2452 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2453 | candidate1); |
| 2454 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 2455 | SetRemoteDescriptionWithoutError(offer); |
| 2456 | ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL); |
| 2457 | ASSERT_TRUE(session_->GetTransportProxy("video") != NULL); |
| 2458 | |
| 2459 | // Pump for 1 second and verify that no candidates are generated. |
| 2460 | talk_base::Thread::Current()->ProcessMessages(1000); |
| 2461 | EXPECT_TRUE(observer_.mline_0_candidates_.empty()); |
| 2462 | EXPECT_TRUE(observer_.mline_1_candidates_.empty()); |
| 2463 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2464 | SessionDescriptionInterface* answer = CreateAnswer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2465 | SetLocalDescriptionWithoutError(answer); |
| 2466 | EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated()); |
| 2467 | EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated()); |
| 2468 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 2469 | } |
| 2470 | |
| 2471 | // This test verifies that crypto parameter is updated in local session |
| 2472 | // description as per security policy set in MediaSessionDescriptionFactory. |
| 2473 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2474 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2475 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2476 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2477 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2478 | |
| 2479 | // Making sure SetLocalDescription correctly sets crypto value in |
| 2480 | // SessionDescription object after de-serialization of sdp string. The value |
| 2481 | // will be set as per MediaSessionDescriptionFactory. |
| 2482 | std::string offer_str; |
| 2483 | offer->ToString(&offer_str); |
| 2484 | SessionDescriptionInterface* jsep_offer_str = |
| 2485 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 2486 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 2487 | EXPECT_TRUE(session_->voice_channel()->secure_required()); |
| 2488 | EXPECT_TRUE(session_->video_channel()->secure_required()); |
| 2489 | } |
| 2490 | |
| 2491 | // This test verifies the crypto parameter when security is disabled. |
| 2492 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2493 | options_.disable_encryption = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2494 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2495 | mediastream_signaling_.SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2496 | talk_base::scoped_ptr<SessionDescriptionInterface> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2497 | CreateOffer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2498 | |
| 2499 | // Making sure SetLocalDescription correctly sets crypto value in |
| 2500 | // SessionDescription object after de-serialization of sdp string. The value |
| 2501 | // will be set as per MediaSessionDescriptionFactory. |
| 2502 | std::string offer_str; |
| 2503 | offer->ToString(&offer_str); |
| 2504 | SessionDescriptionInterface *jsep_offer_str = |
| 2505 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 2506 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 2507 | EXPECT_FALSE(session_->voice_channel()->secure_required()); |
| 2508 | EXPECT_FALSE(session_->video_channel()->secure_required()); |
| 2509 | } |
| 2510 | |
| 2511 | // This test verifies that an answer contains new ufrag and password if an offer |
| 2512 | // with new ufrag and password is received. |
| 2513 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2514 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2515 | cricket::MediaSessionOptions options; |
| 2516 | options.has_audio = true; |
| 2517 | options.has_video = true; |
| 2518 | talk_base::scoped_ptr<JsepSessionDescription> offer( |
| 2519 | CreateRemoteOffer(options)); |
| 2520 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2521 | |
| 2522 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2523 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2524 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2525 | SetLocalDescriptionWithoutError(answer.release()); |
| 2526 | |
| 2527 | // Receive an offer with new ufrag and password. |
| 2528 | options.transport_options.ice_restart = true; |
| 2529 | talk_base::scoped_ptr<JsepSessionDescription> updated_offer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2530 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2531 | SetRemoteDescriptionWithoutError(updated_offer1.release()); |
| 2532 | |
| 2533 | talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2534 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2535 | |
| 2536 | CompareIceUfragAndPassword(updated_answer1->description(), |
| 2537 | session_->local_description()->description(), |
| 2538 | false); |
| 2539 | |
| 2540 | SetLocalDescriptionWithoutError(updated_answer1.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2541 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2542 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2543 | // This test verifies that an answer contains old ufrag and password if an offer |
| 2544 | // with old ufrag and password is received. |
| 2545 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
| 2546 | Init(NULL); |
| 2547 | cricket::MediaSessionOptions options; |
| 2548 | options.has_audio = true; |
| 2549 | options.has_video = true; |
| 2550 | talk_base::scoped_ptr<JsepSessionDescription> offer( |
| 2551 | CreateRemoteOffer(options)); |
| 2552 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2553 | |
| 2554 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2555 | talk_base::scoped_ptr<SessionDescriptionInterface> answer( |
| 2556 | CreateAnswer(NULL)); |
| 2557 | SetLocalDescriptionWithoutError(answer.release()); |
| 2558 | |
| 2559 | // Receive an offer without changed ufrag or password. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2560 | options.transport_options.ice_restart = false; |
| 2561 | talk_base::scoped_ptr<JsepSessionDescription> updated_offer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2562 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2563 | SetRemoteDescriptionWithoutError(updated_offer2.release()); |
| 2564 | |
| 2565 | talk_base::scoped_ptr<SessionDescriptionInterface> updated_answer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2566 | CreateAnswer(NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2567 | |
| 2568 | CompareIceUfragAndPassword(updated_answer2->description(), |
| 2569 | session_->local_description()->description(), |
| 2570 | true); |
| 2571 | |
| 2572 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 2573 | } |
| 2574 | |
| 2575 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2576 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2577 | mediastream_signaling_.SendAudioVideoStream1(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2578 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2579 | const std::string session_id_orig = offer->session_id(); |
| 2580 | const std::string session_version_orig = offer->session_version(); |
| 2581 | SetLocalDescriptionWithoutError(offer); |
| 2582 | |
| 2583 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2584 | video_channel_->set_fail_set_send_codecs(true); |
| 2585 | |
| 2586 | mediastream_signaling_.SendAudioVideoStream2(); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2587 | SessionDescriptionInterface* answer = |
| 2588 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2589 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 2593 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 2594 | // Lets try with only UDP ports. |
| 2595 | allocator_.set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
| 2596 | cricket::PORTALLOCATOR_DISABLE_TCP | |
| 2597 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2598 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 2599 | TestLoopbackCall(); |
| 2600 | } |
| 2601 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2602 | TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2603 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2604 | cricket::MediaSessionOptions options; |
| 2605 | options.has_audio = true; |
| 2606 | options.has_video = true; |
| 2607 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2608 | cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT; |
| 2609 | std::string error_code_str = "ERROR_CONTENT"; |
| 2610 | std::string error_desc = "Fake session error description."; |
| 2611 | session_->SetError(error_code, error_desc); |
| 2612 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2613 | SessionDescriptionInterface* offer = CreateRemoteOffer(options); |
| 2614 | SessionDescriptionInterface* answer = |
| 2615 | CreateRemoteAnswer(offer, options); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2616 | |
| 2617 | std::string action; |
| 2618 | std::ostringstream session_error_msg; |
| 2619 | session_error_msg << kSessionError << error_code_str << ". "; |
| 2620 | session_error_msg << kSessionErrorDesc << error_desc << "."; |
| 2621 | SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer); |
| 2622 | SetLocalDescriptionExpectError(action, session_error_msg.str(), answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
| 2626 | constraints_.reset(new FakeConstraints()); |
| 2627 | constraints_->AddOptional( |
| 2628 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2629 | Init(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2630 | |
| 2631 | SetLocalDescriptionWithDataChannel(); |
| 2632 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 2633 | } |
| 2634 | |
| 2635 | TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
| 2636 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2637 | |
| 2638 | constraints_.reset(new FakeConstraints()); |
| 2639 | constraints_->AddOptional( |
| 2640 | webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2641 | options_.disable_sctp_data_channels = false; |
| 2642 | |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2643 | InitWithDtls(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2644 | |
| 2645 | SetLocalDescriptionWithDataChannel(); |
| 2646 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 2647 | } |
| 2648 | |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 2649 | TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
| 2650 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2651 | |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2652 | InitWithDtls(false); |
| 2653 | |
| 2654 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2655 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2656 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 2657 | } |
| 2658 | |
| 2659 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
| 2660 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2661 | SetFactoryDtlsSrtp(); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2662 | InitWithDtls(false); |
| 2663 | |
| 2664 | // Create remote offer with SCTP. |
| 2665 | cricket::MediaSessionOptions options; |
| 2666 | options.data_channel_type = cricket::DCT_SCTP; |
| 2667 | JsepSessionDescription* offer = |
| 2668 | CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 2669 | SetRemoteDescriptionWithoutError(offer); |
| 2670 | |
| 2671 | // Verifies the answer contains SCTP. |
| 2672 | talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
| 2673 | EXPECT_TRUE(answer != NULL); |
| 2674 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 2675 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2678 | TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
| 2679 | constraints_.reset(new FakeConstraints()); |
| 2680 | constraints_->AddOptional( |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2681 | webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 2682 | InitWithDtls(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2683 | |
| 2684 | SetLocalDescriptionWithDataChannel(); |
| 2685 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 2686 | } |
| 2687 | |
| 2688 | TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
| 2689 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2690 | |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2691 | InitWithDtls(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2692 | |
| 2693 | SetLocalDescriptionWithDataChannel(); |
| 2694 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 2695 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2696 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2697 | TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) { |
| 2698 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2699 | options_.disable_sctp_data_channels = true; |
| 2700 | InitWithDtls(false); |
| 2701 | |
| 2702 | SetLocalDescriptionWithDataChannel(); |
| 2703 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 2704 | } |
| 2705 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2706 | TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
| 2707 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2708 | const int new_send_port = 9998; |
| 2709 | const int new_recv_port = 7775; |
| 2710 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2711 | InitWithDtls(false); |
| 2712 | SetFactoryDtlsSrtp(); |
| 2713 | |
| 2714 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 2715 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 2716 | // let the session description get parsed. That'll get the proper codecs |
| 2717 | // into the stream. |
| 2718 | cricket::MediaSessionOptions options; |
| 2719 | JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort( |
| 2720 | "stream1", new_send_port, options); |
| 2721 | |
| 2722 | // SetRemoteDescription will take the ownership of the offer. |
| 2723 | SetRemoteDescriptionWithoutError(offer); |
| 2724 | |
| 2725 | SessionDescriptionInterface* answer = ChangeSDPSctpPort( |
| 2726 | new_recv_port, CreateAnswer(NULL)); |
| 2727 | ASSERT_TRUE(answer != NULL); |
| 2728 | |
| 2729 | // Now set the local description, which'll take ownership of the answer. |
| 2730 | SetLocalDescriptionWithoutError(answer); |
| 2731 | |
| 2732 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 2733 | // and pass it all the way down. |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 2734 | webrtc::InternalDataChannelInit dci; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2735 | dci.reliable = true; |
| 2736 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 2737 | talk_base::scoped_refptr<webrtc::DataChannel> dc = |
| 2738 | session_->CreateDataChannel("datachannel", &dci); |
| 2739 | |
| 2740 | cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0); |
| 2741 | int portnum = -1; |
| 2742 | ASSERT_TRUE(ch != NULL); |
| 2743 | ASSERT_EQ(1UL, ch->send_codecs().size()); |
| 2744 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id); |
| 2745 | EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName, |
| 2746 | ch->send_codecs()[0].name.c_str())); |
| 2747 | EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 2748 | &portnum)); |
| 2749 | EXPECT_EQ(new_send_port, portnum); |
| 2750 | |
| 2751 | ASSERT_EQ(1UL, ch->recv_codecs().size()); |
| 2752 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id); |
| 2753 | EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName, |
| 2754 | ch->recv_codecs()[0].name.c_str())); |
| 2755 | EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 2756 | &portnum)); |
| 2757 | EXPECT_EQ(new_recv_port, portnum); |
| 2758 | } |
| 2759 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2760 | // Verifies that CreateOffer succeeds when CreateOffer is called before async |
| 2761 | // identity generation is finished. |
| 2762 | TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { |
| 2763 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2764 | InitWithDtls(false); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2765 | |
| 2766 | EXPECT_TRUE(session_->waiting_for_identity()); |
| 2767 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2768 | EXPECT_TRUE(offer != NULL); |
| 2769 | } |
| 2770 | |
| 2771 | // Verifies that CreateAnswer succeeds when CreateOffer is called before async |
| 2772 | // identity generation is finished. |
| 2773 | TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { |
| 2774 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2775 | InitWithDtls(false); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2776 | |
| 2777 | cricket::MediaSessionOptions options; |
| 2778 | scoped_ptr<JsepSessionDescription> offer( |
| 2779 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 2780 | ASSERT_TRUE(offer.get() != NULL); |
| 2781 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2782 | |
| 2783 | talk_base::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL)); |
| 2784 | EXPECT_TRUE(answer != NULL); |
| 2785 | } |
| 2786 | |
| 2787 | // Verifies that CreateOffer succeeds when CreateOffer is called after async |
| 2788 | // identity generation is finished. |
| 2789 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { |
| 2790 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2791 | InitWithDtls(false); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2792 | |
| 2793 | EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); |
| 2794 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2795 | EXPECT_TRUE(offer != NULL); |
| 2796 | } |
| 2797 | |
| 2798 | // Verifies that CreateOffer fails when CreateOffer is called after async |
| 2799 | // identity generation fails. |
| 2800 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { |
| 2801 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 7666db7 | 2013-08-22 14:45:42 +0000 | [diff] [blame] | 2802 | InitWithDtls(true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2803 | |
| 2804 | EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); |
| 2805 | talk_base::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL)); |
| 2806 | EXPECT_TRUE(offer == NULL); |
| 2807 | } |
| 2808 | |
| 2809 | // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made |
| 2810 | // before async identity generation is finished. |
| 2811 | TEST_F(WebRtcSessionTest, |
| 2812 | TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { |
| 2813 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2814 | VerifyMultipleAsyncCreateDescription( |
| 2815 | true, CreateSessionDescriptionRequest::kOffer); |
| 2816 | } |
| 2817 | |
| 2818 | // Verifies that CreateOffer fails when Multiple CreateOffer calls are made |
| 2819 | // before async identity generation fails. |
| 2820 | TEST_F(WebRtcSessionTest, |
| 2821 | TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) { |
| 2822 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2823 | VerifyMultipleAsyncCreateDescription( |
| 2824 | false, CreateSessionDescriptionRequest::kOffer); |
| 2825 | } |
| 2826 | |
| 2827 | // Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made |
| 2828 | // before async identity generation is finished. |
| 2829 | TEST_F(WebRtcSessionTest, |
| 2830 | TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) { |
| 2831 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2832 | VerifyMultipleAsyncCreateDescription( |
| 2833 | true, CreateSessionDescriptionRequest::kAnswer); |
| 2834 | } |
| 2835 | |
| 2836 | // Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made |
| 2837 | // before async identity generation fails. |
| 2838 | TEST_F(WebRtcSessionTest, |
| 2839 | TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) { |
| 2840 | MAYBE_SKIP_TEST(talk_base::SSLStreamAdapter::HaveDtlsSrtp); |
| 2841 | VerifyMultipleAsyncCreateDescription( |
| 2842 | false, CreateSessionDescriptionRequest::kAnswer); |
| 2843 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2844 | |
| 2845 | // Verifies that setRemoteDescription fails when DTLS is disabled and the remote |
| 2846 | // offer has no SDES crypto but only DTLS fingerprint. |
| 2847 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { |
| 2848 | // Init without DTLS. |
| 2849 | Init(NULL); |
| 2850 | // Create a remote offer with secured transport disabled. |
| 2851 | cricket::MediaSessionOptions options; |
| 2852 | JsepSessionDescription* offer(CreateRemoteOffer( |
| 2853 | options, cricket::SEC_DISABLED)); |
| 2854 | // Adds a DTLS fingerprint to the remote offer. |
| 2855 | cricket::SessionDescription* sdp = offer->description(); |
| 2856 | TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 2857 | ASSERT_TRUE(audio != NULL); |
| 2858 | ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); |
| 2859 | audio->description.identity_fingerprint.reset( |
| 2860 | talk_base::SSLFingerprint::CreateFromRfc4572( |
| 2861 | talk_base::DIGEST_SHA_256, kFakeDtlsFingerprint)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame^] | 2862 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesAndDtlsDisabled, |
| 2863 | offer); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 2866 | // This test verifies DSCP is properly applied on the media channels. |
| 2867 | TEST_F(WebRtcSessionTest, TestDscpConstraint) { |
| 2868 | constraints_.reset(new FakeConstraints()); |
| 2869 | constraints_->AddOptional( |
| 2870 | webrtc::MediaConstraintsInterface::kEnableDscp, true); |
| 2871 | Init(NULL); |
| 2872 | mediastream_signaling_.SendAudioVideoStream1(); |
| 2873 | SessionDescriptionInterface* offer = CreateOffer(NULL); |
| 2874 | |
| 2875 | SetLocalDescriptionWithoutError(offer); |
| 2876 | |
| 2877 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2878 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2879 | |
| 2880 | ASSERT_TRUE(video_channel_ != NULL); |
| 2881 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2882 | cricket::AudioOptions audio_options; |
| 2883 | EXPECT_TRUE(voice_channel_->GetOptions(&audio_options)); |
| 2884 | cricket::VideoOptions video_options; |
| 2885 | EXPECT_TRUE(video_channel_->GetOptions(&video_options)); |
| 2886 | EXPECT_TRUE(audio_options.dscp.IsSet()); |
| 2887 | EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false)); |
| 2888 | EXPECT_TRUE(video_options.dscp.IsSet()); |
| 2889 | EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false)); |
| 2890 | } |
| 2891 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2892 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 2893 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 2894 | // called more than once without returning to IceGatheringGathering. |