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