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