henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 11 | #include <utility> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 14 | #include "webrtc/api/audiotrack.h" |
| 15 | #include "webrtc/api/fakemediacontroller.h" |
| 16 | #include "webrtc/api/fakemetricsobserver.h" |
| 17 | #include "webrtc/api/jsepicecandidate.h" |
| 18 | #include "webrtc/api/jsepsessiondescription.h" |
| 19 | #include "webrtc/api/peerconnection.h" |
| 20 | #include "webrtc/api/sctputils.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 21 | #include "webrtc/api/test/fakedtlsidentitystore.h" |
| 22 | #include "webrtc/api/videotrack.h" |
| 23 | #include "webrtc/api/webrtcsession.h" |
| 24 | #include "webrtc/api/webrtcsessiondescriptionfactory.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 25 | #include "webrtc/base/fakenetwork.h" |
| 26 | #include "webrtc/base/firewallsocketserver.h" |
| 27 | #include "webrtc/base/gunit.h" |
| 28 | #include "webrtc/base/logging.h" |
| 29 | #include "webrtc/base/network.h" |
| 30 | #include "webrtc/base/physicalsocketserver.h" |
| 31 | #include "webrtc/base/ssladapter.h" |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 32 | #include "webrtc/base/sslidentity.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 33 | #include "webrtc/base/sslstreamadapter.h" |
| 34 | #include "webrtc/base/stringutils.h" |
| 35 | #include "webrtc/base/thread.h" |
| 36 | #include "webrtc/base/virtualsocketserver.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 37 | #include "webrtc/media/base/fakemediaengine.h" |
| 38 | #include "webrtc/media/base/fakevideorenderer.h" |
| 39 | #include "webrtc/media/base/mediachannel.h" |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 40 | #include "webrtc/media/engine/fakewebrtccall.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 41 | #include "webrtc/p2p/base/stunserver.h" |
| 42 | #include "webrtc/p2p/base/teststunserver.h" |
| 43 | #include "webrtc/p2p/base/testturnserver.h" |
| 44 | #include "webrtc/p2p/base/transportchannel.h" |
| 45 | #include "webrtc/p2p/client/basicportallocator.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 46 | #include "webrtc/pc/channelmanager.h" |
| 47 | #include "webrtc/pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
| 49 | #define MAYBE_SKIP_TEST(feature) \ |
| 50 | if (!(feature())) { \ |
| 51 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 52 | return; \ |
| 53 | } |
| 54 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | using cricket::TransportInfo; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 57 | using rtc::SocketAddress; |
| 58 | using rtc::scoped_ptr; |
| 59 | using rtc::Thread; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | using webrtc::CreateSessionDescription; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 61 | using webrtc::CreateSessionDescriptionObserver; |
| 62 | using webrtc::CreateSessionDescriptionRequest; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 63 | using webrtc::DataChannel; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 64 | using webrtc::DtlsIdentityStoreInterface; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 65 | using webrtc::FakeMetricsObserver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | using webrtc::IceCandidateCollection; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 67 | using webrtc::InternalDataChannelInit; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | using webrtc::JsepIceCandidate; |
| 69 | using webrtc::JsepSessionDescription; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 70 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | using webrtc::PeerConnectionInterface; |
| 72 | using webrtc::SessionDescriptionInterface; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 73 | using webrtc::SessionStats; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | using webrtc::StreamCollection; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 75 | using webrtc::WebRtcSession; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 76 | using webrtc::kBundleWithoutRtcpMux; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 77 | using webrtc::kCreateChannelFailed; |
| 78 | using webrtc::kInvalidSdp; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | using webrtc::kMlineMismatch; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 80 | using webrtc::kPushDownTDFailed; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 81 | using webrtc::kSdpWithoutIceUfragPwd; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 82 | using webrtc::kSdpWithoutDtlsFingerprint; |
| 83 | using webrtc::kSdpWithoutSdesCrypto; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | using webrtc::kSessionError; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 85 | using webrtc::kSessionErrorDesc; |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 86 | using webrtc::kMaxUnsignalledRecvStreams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 88 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 89 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 90 | static const int kClientAddrPort = 0; |
| 91 | static const char kClientAddrHost1[] = "11.11.11.11"; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 92 | static const char kClientIPv6AddrHost1[] = |
| 93 | "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 94 | static const char kClientAddrHost2[] = "22.22.22.22"; |
| 95 | static const char kStunAddrHost[] = "99.99.99.1"; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 96 | static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); |
| 97 | static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 98 | static const char kTurnUsername[] = "test"; |
| 99 | static const char kTurnPassword[] = "test"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | |
| 101 | static const char kSessionVersion[] = "1"; |
| 102 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | // Media index of candidates belonging to the first media content. |
| 104 | static const int kMediaContentIndex0 = 0; |
| 105 | static const char kMediaContentName0[] = "audio"; |
| 106 | |
| 107 | // Media index of candidates belonging to the second media content. |
| 108 | static const int kMediaContentIndex1 = 1; |
| 109 | static const char kMediaContentName1[] = "video"; |
| 110 | |
| 111 | static const int kIceCandidatesTimeout = 10000; |
| 112 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 113 | static const char kFakeDtlsFingerprint[] = |
| 114 | "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:" |
| 115 | "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24"; |
| 116 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 117 | static const char kTooLongIceUfragPwd[] = |
| 118 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 119 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 120 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 121 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"; |
| 122 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 123 | static const char kSdpWithRtx[] = |
| 124 | "v=0\r\n" |
| 125 | "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n" |
| 126 | "s=-\r\n" |
| 127 | "t=0 0\r\n" |
| 128 | "a=msid-semantic: WMS stream1\r\n" |
| 129 | "m=video 9 RTP/SAVPF 0 96\r\n" |
| 130 | "c=IN IP4 0.0.0.0\r\n" |
| 131 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 132 | "a=ice-ufrag:CerjGp19G7wpXwl7\r\n" |
| 133 | "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n" |
| 134 | "a=mid:video\r\n" |
| 135 | "a=sendrecv\r\n" |
| 136 | "a=rtcp-mux\r\n" |
| 137 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 138 | "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n" |
| 139 | "a=rtpmap:0 fake_video_codec/90000\r\n" |
| 140 | "a=rtpmap:96 rtx/90000\r\n" |
| 141 | "a=fmtp:96 apt=0\r\n"; |
| 142 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 143 | static const char kStream1[] = "stream1"; |
| 144 | static const char kVideoTrack1[] = "video1"; |
| 145 | static const char kAudioTrack1[] = "audio1"; |
| 146 | |
| 147 | static const char kStream2[] = "stream2"; |
| 148 | static const char kVideoTrack2[] = "video2"; |
| 149 | static const char kAudioTrack2[] = "audio2"; |
| 150 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 151 | enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; |
| 152 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | class MockIceObserver : public webrtc::IceObserver { |
| 154 | public: |
| 155 | MockIceObserver() |
| 156 | : oncandidatesready_(false), |
| 157 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 158 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 159 | } |
| 160 | |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 161 | void OnIceConnectionChange( |
| 162 | PeerConnectionInterface::IceConnectionState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | ice_connection_state_ = new_state; |
| 164 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 165 | void OnIceGatheringChange( |
| 166 | PeerConnectionInterface::IceGatheringState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | // We can never transition back to "new". |
| 168 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 169 | ice_gathering_state_ = new_state; |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 170 | oncandidatesready_ = |
| 171 | new_state == PeerConnectionInterface::kIceGatheringComplete; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // Found a new candidate. |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 175 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 176 | switch (candidate->sdp_mline_index()) { |
| 177 | case kMediaContentIndex0: |
| 178 | mline_0_candidates_.push_back(candidate->candidate()); |
| 179 | break; |
| 180 | case kMediaContentIndex1: |
| 181 | mline_1_candidates_.push_back(candidate->candidate()); |
| 182 | break; |
| 183 | default: |
| 184 | ASSERT(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 186 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | // The ICE gathering state should always be Gathering when a candidate is |
| 188 | // received (or possibly Completed in the case of the final candidate). |
| 189 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 190 | } |
| 191 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | bool oncandidatesready_; |
| 193 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 194 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 195 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 196 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
| 197 | }; |
| 198 | |
| 199 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 200 | public: |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 201 | WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 202 | rtc::Thread* signaling_thread, |
| 203 | rtc::Thread* worker_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | cricket::PortAllocator* port_allocator, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 205 | webrtc::IceObserver* ice_observer) |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 206 | : WebRtcSession(media_controller, |
| 207 | signaling_thread, |
| 208 | worker_thread, |
| 209 | port_allocator) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | RegisterIceObserver(ice_observer); |
| 211 | } |
| 212 | virtual ~WebRtcSessionForTest() {} |
| 213 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 214 | // Note that these methods are only safe to use if the signaling thread |
| 215 | // is the same as the worker thread |
| 216 | cricket::TransportChannel* voice_rtp_transport_channel() { |
| 217 | return rtp_transport_channel(voice_channel()); |
| 218 | } |
| 219 | |
| 220 | cricket::TransportChannel* voice_rtcp_transport_channel() { |
| 221 | return rtcp_transport_channel(voice_channel()); |
| 222 | } |
| 223 | |
| 224 | cricket::TransportChannel* video_rtp_transport_channel() { |
| 225 | return rtp_transport_channel(video_channel()); |
| 226 | } |
| 227 | |
| 228 | cricket::TransportChannel* video_rtcp_transport_channel() { |
| 229 | return rtcp_transport_channel(video_channel()); |
| 230 | } |
| 231 | |
| 232 | cricket::TransportChannel* data_rtp_transport_channel() { |
| 233 | return rtp_transport_channel(data_channel()); |
| 234 | } |
| 235 | |
| 236 | cricket::TransportChannel* data_rtcp_transport_channel() { |
| 237 | return rtcp_transport_channel(data_channel()); |
| 238 | } |
| 239 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | using webrtc::WebRtcSession::SetAudioPlayout; |
| 241 | using webrtc::WebRtcSession::SetAudioSend; |
| 242 | using webrtc::WebRtcSession::SetCaptureDevice; |
| 243 | using webrtc::WebRtcSession::SetVideoPlayout; |
| 244 | using webrtc::WebRtcSession::SetVideoSend; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 245 | |
| 246 | private: |
| 247 | cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) { |
| 248 | if (!ch) { |
| 249 | return nullptr; |
| 250 | } |
| 251 | return ch->transport_channel(); |
| 252 | } |
| 253 | |
| 254 | cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) { |
| 255 | if (!ch) { |
| 256 | return nullptr; |
| 257 | } |
| 258 | return ch->rtcp_transport_channel(); |
| 259 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 262 | class WebRtcSessionCreateSDPObserverForTest |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 263 | : public rtc::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 264 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 265 | enum State { |
| 266 | kInit, |
| 267 | kFailed, |
| 268 | kSucceeded, |
| 269 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 270 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 271 | |
| 272 | // CreateSessionDescriptionObserver implementation. |
| 273 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 274 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 275 | state_ = kSucceeded; |
| 276 | } |
| 277 | virtual void OnFailure(const std::string& error) { |
| 278 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 279 | } |
| 280 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 281 | SessionDescriptionInterface* description() { return description_.get(); } |
| 282 | |
| 283 | SessionDescriptionInterface* ReleaseDescription() { |
| 284 | return description_.release(); |
| 285 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 286 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 287 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 288 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 289 | protected: |
| 290 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 291 | |
| 292 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 293 | rtc::scoped_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 294 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 297 | class FakeAudioSource : public cricket::AudioSource { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 298 | public: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 299 | FakeAudioSource() : sink_(NULL) {} |
| 300 | virtual ~FakeAudioSource() { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 301 | if (sink_) |
| 302 | sink_->OnClose(); |
| 303 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 304 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 305 | void SetSink(Sink* sink) override { sink_ = sink; } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 306 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 307 | const cricket::AudioSource::Sink* sink() const { return sink_; } |
| 308 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 309 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 310 | cricket::AudioSource::Sink* sink_; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 311 | }; |
| 312 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 313 | class WebRtcSessionTest |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 314 | : public testing::TestWithParam<RTCCertificateGenerationMethod>, |
| 315 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | protected: |
| 317 | // TODO Investigate why ChannelManager crashes, if it's created |
| 318 | // after stun_server. |
| 319 | WebRtcSessionTest() |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 320 | : media_engine_(new cricket::FakeMediaEngine()), |
| 321 | data_engine_(new cricket::FakeDataEngine()), |
| 322 | channel_manager_( |
| 323 | new cricket::ChannelManager(media_engine_, |
| 324 | data_engine_, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 325 | rtc::Thread::Current())), |
| 326 | fake_call_(webrtc::Call::Config()), |
| 327 | media_controller_( |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 328 | webrtc::MediaControllerInterface::Create(cricket::MediaConfig(), |
| 329 | rtc::Thread::Current(), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 330 | channel_manager_.get())), |
| 331 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 332 | desc_factory_( |
| 333 | new cricket::MediaSessionDescriptionFactory(channel_manager_.get(), |
| 334 | tdesc_factory_.get())), |
| 335 | pss_(new rtc::PhysicalSocketServer), |
| 336 | vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 337 | fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 338 | ss_scope_(fss_.get()), |
| 339 | stun_socket_addr_( |
| 340 | rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)), |
| 341 | stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 342 | stun_socket_addr_)), |
| 343 | turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
| 344 | metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 345 | cricket::ServerAddresses stun_servers; |
| 346 | stun_servers.insert(stun_socket_addr_); |
| 347 | allocator_.reset(new cricket::BasicPortAllocator( |
| 348 | &network_manager_, |
| 349 | stun_servers, |
| 350 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 351 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 352 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 353 | EXPECT_TRUE(channel_manager_->Init()); |
| 354 | desc_factory_->set_add_legacy_streams(false); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 355 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | void AddInterface(const SocketAddress& addr) { |
| 359 | network_manager_.AddInterface(addr); |
| 360 | } |
| 361 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 362 | // If |dtls_identity_store| != null or |rtc_configuration| contains |
| 363 | // |certificates| then DTLS will be enabled unless explicitly disabled by |
| 364 | // |rtc_configuration| options. When DTLS is enabled a certificate will be |
| 365 | // used if provided, otherwise one will be generated using the |
| 366 | // |dtls_identity_store|. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 367 | void Init( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 368 | rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 369 | ASSERT_TRUE(session_.get() == NULL); |
| 370 | session_.reset(new WebRtcSessionForTest( |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 371 | media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 372 | allocator_.get(), &observer_)); |
| 373 | session_->SignalDataChannelOpenMessage.connect( |
| 374 | this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
deadbeef | 057ecf0 | 2016-01-20 14:30:43 -0800 | [diff] [blame] | 375 | session_->GetOnDestroyedSignal()->connect( |
| 376 | this, &WebRtcSessionTest::OnSessionDestroyed); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 377 | |
| 378 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 379 | observer_.ice_connection_state_); |
| 380 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 381 | observer_.ice_gathering_state_); |
| 382 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 383 | EXPECT_TRUE(session_->Initialize(options_, std::move(dtls_identity_store), |
| 384 | configuration_)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 385 | session_->set_metrics_observer(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 386 | } |
| 387 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 388 | void OnDataChannelOpenMessage(const std::string& label, |
| 389 | const InternalDataChannelInit& config) { |
| 390 | last_data_channel_label_ = label; |
| 391 | last_data_channel_config_ = config; |
| 392 | } |
| 393 | |
deadbeef | 057ecf0 | 2016-01-20 14:30:43 -0800 | [diff] [blame] | 394 | void OnSessionDestroyed() { session_destroyed_ = true; } |
| 395 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 396 | void Init() { Init(nullptr); } |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 397 | |
| 398 | void InitWithIceTransport( |
| 399 | PeerConnectionInterface::IceTransportsType ice_transport_type) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 400 | configuration_.type = ice_transport_type; |
| 401 | Init(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void InitWithBundlePolicy( |
| 405 | PeerConnectionInterface::BundlePolicy bundle_policy) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 406 | configuration_.bundle_policy = bundle_policy; |
| 407 | Init(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void InitWithRtcpMuxPolicy( |
| 411 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 412 | PeerConnectionInterface::RTCConfiguration configuration; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 413 | configuration_.rtcp_mux_policy = rtcp_mux_policy; |
| 414 | Init(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 417 | // Successfully init with DTLS; with a certificate generated and supplied or |
| 418 | // with a store that generates it for us. |
| 419 | void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
| 420 | rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 421 | if (cert_gen_method == ALREADY_GENERATED) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 422 | configuration_.certificates.push_back( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 423 | FakeDtlsIdentityStore::GenerateCertificate()); |
| 424 | } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
| 425 | dtls_identity_store.reset(new FakeDtlsIdentityStore()); |
| 426 | dtls_identity_store->set_should_fail(false); |
| 427 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 428 | RTC_CHECK(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 429 | } |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 430 | Init(std::move(dtls_identity_store)); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // Init with DTLS with a store that will fail to generate a certificate. |
| 434 | void InitWithDtlsIdentityGenFail() { |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 435 | rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
| 436 | new FakeDtlsIdentityStore()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 437 | dtls_identity_store->set_should_fail(true); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 438 | Init(std::move(dtls_identity_store)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 439 | } |
| 440 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 441 | void InitWithDtmfCodec() { |
| 442 | // Add kTelephoneEventCodec for dtmf test. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 443 | const cricket::AudioCodec kTelephoneEventCodec( |
| 444 | 106, "telephone-event", 8000, 0, 1, 0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 445 | std::vector<cricket::AudioCodec> codecs; |
| 446 | codecs.push_back(kTelephoneEventCodec); |
| 447 | media_engine_->SetAudioCodecs(codecs); |
| 448 | desc_factory_->set_audio_codecs(codecs); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 449 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 450 | } |
| 451 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 452 | void SendAudioVideoStream1() { |
| 453 | send_stream_1_ = true; |
| 454 | send_stream_2_ = false; |
| 455 | send_audio_ = true; |
| 456 | send_video_ = true; |
| 457 | } |
| 458 | |
| 459 | void SendAudioVideoStream2() { |
| 460 | send_stream_1_ = false; |
| 461 | send_stream_2_ = true; |
| 462 | send_audio_ = true; |
| 463 | send_video_ = true; |
| 464 | } |
| 465 | |
| 466 | void SendAudioVideoStream1And2() { |
| 467 | send_stream_1_ = true; |
| 468 | send_stream_2_ = true; |
| 469 | send_audio_ = true; |
| 470 | send_video_ = true; |
| 471 | } |
| 472 | |
| 473 | void SendNothing() { |
| 474 | send_stream_1_ = false; |
| 475 | send_stream_2_ = false; |
| 476 | send_audio_ = false; |
| 477 | send_video_ = false; |
| 478 | } |
| 479 | |
| 480 | void SendAudioOnlyStream2() { |
| 481 | send_stream_1_ = false; |
| 482 | send_stream_2_ = true; |
| 483 | send_audio_ = true; |
| 484 | send_video_ = false; |
| 485 | } |
| 486 | |
| 487 | void SendVideoOnlyStream2() { |
| 488 | send_stream_1_ = false; |
| 489 | send_stream_2_ = true; |
| 490 | send_audio_ = false; |
| 491 | send_video_ = true; |
| 492 | } |
| 493 | |
| 494 | void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) { |
| 495 | if (send_stream_1_ && send_audio_) { |
| 496 | session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 497 | kStream1); |
| 498 | } |
| 499 | if (send_stream_1_ && send_video_) { |
| 500 | session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 501 | kStream1); |
| 502 | } |
| 503 | if (send_stream_2_ && send_audio_) { |
| 504 | session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 505 | kStream2); |
| 506 | } |
| 507 | if (send_stream_2_ && send_video_) { |
| 508 | session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 509 | kStream2); |
| 510 | } |
| 511 | if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) { |
| 512 | session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, |
| 513 | data_channel_->label(), |
| 514 | data_channel_->label()); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | void GetOptionsForOffer( |
| 519 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 520 | cricket::MediaSessionOptions* session_options) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 521 | ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, session_options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 522 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 523 | AddStreamsToOptions(session_options); |
| 524 | if (rtc_options.offer_to_receive_audio == |
| 525 | RTCOfferAnswerOptions::kUndefined) { |
| 526 | session_options->recv_audio = |
| 527 | session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO); |
| 528 | } |
| 529 | if (rtc_options.offer_to_receive_video == |
| 530 | RTCOfferAnswerOptions::kUndefined) { |
| 531 | session_options->recv_video = |
| 532 | session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); |
| 533 | } |
| 534 | session_options->bundle_enabled = |
| 535 | session_options->bundle_enabled && |
| 536 | (session_options->has_audio() || session_options->has_video() || |
| 537 | session_options->has_data()); |
| 538 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 539 | if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { |
| 540 | session_options->data_channel_type = cricket::DCT_SCTP; |
| 541 | } |
| 542 | } |
| 543 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 544 | void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 545 | // ParseConstraintsForAnswer is used to set some defaults. |
| 546 | ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 547 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 548 | AddStreamsToOptions(session_options); |
| 549 | session_options->bundle_enabled = |
| 550 | session_options->bundle_enabled && |
| 551 | (session_options->has_audio() || session_options->has_video() || |
| 552 | session_options->has_data()); |
| 553 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 554 | if (session_->data_channel_type() == cricket::DCT_SCTP) { |
| 555 | session_options->data_channel_type = cricket::DCT_SCTP; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | // Creates a local offer and applies it. Starts ICE. |
| 560 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 561 | // to decide which streams to create. |
| 562 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 563 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | SetLocalDescriptionWithoutError(offer); |
| 565 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 566 | observer_.ice_gathering_state_, |
| 567 | kIceCandidatesTimeout); |
| 568 | } |
| 569 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 570 | SessionDescriptionInterface* CreateOffer() { |
| 571 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 572 | options.offer_to_receive_audio = |
| 573 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 574 | |
| 575 | return CreateOffer(options); |
| 576 | } |
| 577 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 578 | SessionDescriptionInterface* CreateOffer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 579 | const PeerConnectionInterface::RTCOfferAnswerOptions options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 580 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 581 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 582 | cricket::MediaSessionOptions session_options; |
| 583 | GetOptionsForOffer(options, &session_options); |
| 584 | session_->CreateOffer(observer, options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 585 | EXPECT_TRUE_WAIT( |
| 586 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 587 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 588 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | SessionDescriptionInterface* CreateAnswer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 592 | const cricket::MediaSessionOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 593 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 594 | = new WebRtcSessionCreateSDPObserverForTest(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 595 | cricket::MediaSessionOptions session_options = options; |
| 596 | GetOptionsForAnswer(&session_options); |
| 597 | // Overwrite recv_audio and recv_video with passed-in values. |
| 598 | session_options.recv_video = options.recv_video; |
| 599 | session_options.recv_audio = options.recv_audio; |
| 600 | session_->CreateAnswer(observer, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 601 | EXPECT_TRUE_WAIT( |
| 602 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 603 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 604 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 605 | } |
| 606 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 607 | SessionDescriptionInterface* CreateAnswer() { |
| 608 | cricket::MediaSessionOptions options; |
| 609 | options.recv_video = true; |
| 610 | options.recv_audio = true; |
| 611 | return CreateAnswer(options); |
| 612 | } |
| 613 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 614 | bool ChannelsExist() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 615 | return (session_->voice_channel() != NULL && |
| 616 | session_->video_channel() != NULL); |
| 617 | } |
| 618 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 619 | void VerifyCryptoParams(const cricket::SessionDescription* sdp) { |
| 620 | ASSERT_TRUE(session_.get() != NULL); |
| 621 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 622 | ASSERT_TRUE(content != NULL); |
| 623 | const cricket::AudioContentDescription* audio_content = |
| 624 | static_cast<const cricket::AudioContentDescription*>( |
| 625 | content->description); |
| 626 | ASSERT_TRUE(audio_content != NULL); |
| 627 | ASSERT_EQ(1U, audio_content->cryptos().size()); |
| 628 | ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); |
| 629 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 630 | audio_content->cryptos()[0].cipher_suite); |
| 631 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 632 | audio_content->protocol()); |
| 633 | |
| 634 | content = cricket::GetFirstVideoContent(sdp); |
| 635 | ASSERT_TRUE(content != NULL); |
| 636 | const cricket::VideoContentDescription* video_content = |
| 637 | static_cast<const cricket::VideoContentDescription*>( |
| 638 | content->description); |
| 639 | ASSERT_TRUE(video_content != NULL); |
| 640 | ASSERT_EQ(1U, video_content->cryptos().size()); |
| 641 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 642 | video_content->cryptos()[0].cipher_suite); |
| 643 | ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); |
| 644 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 645 | video_content->protocol()); |
| 646 | } |
| 647 | |
| 648 | void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { |
| 649 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 650 | ASSERT_TRUE(content != NULL); |
| 651 | const cricket::AudioContentDescription* audio_content = |
| 652 | static_cast<const cricket::AudioContentDescription*>( |
| 653 | content->description); |
| 654 | ASSERT_TRUE(audio_content != NULL); |
| 655 | ASSERT_EQ(0U, audio_content->cryptos().size()); |
| 656 | |
| 657 | content = cricket::GetFirstVideoContent(sdp); |
| 658 | ASSERT_TRUE(content != NULL); |
| 659 | const cricket::VideoContentDescription* video_content = |
| 660 | static_cast<const cricket::VideoContentDescription*>( |
| 661 | content->description); |
| 662 | ASSERT_TRUE(video_content != NULL); |
| 663 | ASSERT_EQ(0U, video_content->cryptos().size()); |
| 664 | |
| 665 | if (dtls) { |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 666 | EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | audio_content->protocol()); |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 668 | EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 669 | video_content->protocol()); |
| 670 | } else { |
| 671 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 672 | audio_content->protocol()); |
| 673 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 674 | video_content->protocol()); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | // Set the internal fake description factories to do DTLS-SRTP. |
| 679 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 680 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 681 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 682 | rtc::ToString(rtc::CreateRandomId()); |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 683 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 684 | tdesc_factory_->set_certificate( |
| 685 | rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( |
| 686 | rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 687 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 688 | } |
| 689 | |
| 690 | void VerifyFingerprintStatus(const cricket::SessionDescription* sdp, |
| 691 | bool expected) { |
| 692 | const TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 693 | ASSERT_TRUE(audio != NULL); |
| 694 | ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 695 | const TransportInfo* video = sdp->GetTransportInfoByName("video"); |
| 696 | ASSERT_TRUE(video != NULL); |
| 697 | ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | void VerifyAnswerFromNonCryptoOffer() { |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 701 | // Create an SDP without Crypto. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 702 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 703 | options.recv_video = true; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 704 | JsepSessionDescription* offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 705 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 706 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 707 | VerifyNoCryptoParams(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 708 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
| 709 | offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 710 | const webrtc::SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | // Answer should be NULL as no crypto params in offer. |
| 712 | ASSERT_TRUE(answer == NULL); |
| 713 | } |
| 714 | |
| 715 | void VerifyAnswerFromCryptoOffer() { |
| 716 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 717 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 718 | options.bundle_enabled = true; |
| 719 | scoped_ptr<JsepSessionDescription> offer( |
| 720 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 721 | ASSERT_TRUE(offer.get() != NULL); |
| 722 | VerifyCryptoParams(offer->description()); |
| 723 | SetRemoteDescriptionWithoutError(offer.release()); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 724 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 725 | ASSERT_TRUE(answer.get() != NULL); |
| 726 | VerifyCryptoParams(answer->description()); |
| 727 | } |
| 728 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 729 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 730 | const cricket::SessionDescription* desc2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 731 | if (desc1->contents().size() != desc2->contents().size()) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 732 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | const cricket::ContentInfos& contents = desc1->contents(); |
| 736 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 737 | |
| 738 | for (; it != contents.end(); ++it) { |
| 739 | const cricket::TransportDescription* transport_desc1 = |
| 740 | desc1->GetTransportDescriptionByName(it->name); |
| 741 | const cricket::TransportDescription* transport_desc2 = |
| 742 | desc2->GetTransportDescriptionByName(it->name); |
| 743 | if (!transport_desc1 || !transport_desc2) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 744 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 745 | } |
| 746 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 747 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 748 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | } |
| 750 | } |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 751 | return true; |
| 752 | } |
| 753 | |
| 754 | // Compares ufrag/password only for the specified |media_type|. |
| 755 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 756 | const cricket::SessionDescription* desc2, |
| 757 | cricket::MediaType media_type) { |
| 758 | if (desc1->contents().size() != desc2->contents().size()) { |
| 759 | return false; |
| 760 | } |
| 761 | |
| 762 | const cricket::ContentInfo* cinfo = |
| 763 | cricket::GetFirstMediaContent(desc1->contents(), media_type); |
| 764 | const cricket::TransportDescription* transport_desc1 = |
| 765 | desc1->GetTransportDescriptionByName(cinfo->name); |
| 766 | const cricket::TransportDescription* transport_desc2 = |
| 767 | desc2->GetTransportDescriptionByName(cinfo->name); |
| 768 | if (!transport_desc1 || !transport_desc2) { |
| 769 | return false; |
| 770 | } |
| 771 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 772 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 773 | return false; |
| 774 | } |
| 775 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 776 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 777 | |
| 778 | void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 779 | std::string *sdp) { |
| 780 | const cricket::SessionDescription* desc = current_desc->description(); |
| 781 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 782 | |
| 783 | const cricket::ContentInfos& contents = desc->contents(); |
| 784 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 785 | // Replace ufrag and pwd lines with empty strings. |
| 786 | for (; it != contents.end(); ++it) { |
| 787 | const cricket::TransportDescription* transport_desc = |
| 788 | desc->GetTransportDescriptionByName(it->name); |
| 789 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 790 | + "\r\n"; |
| 791 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 792 | + "\r\n"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 793 | rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 794 | "", 0, |
| 795 | sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 796 | rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 797 | "", 0, |
| 798 | sdp); |
| 799 | } |
| 800 | } |
| 801 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 802 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 803 | const std::string& ufrag, |
| 804 | const std::string& pwd) { |
| 805 | cricket::SessionDescription* desc = current_desc->description(); |
| 806 | for (TransportInfo& transport_info : desc->transport_infos()) { |
| 807 | cricket::TransportDescription& transport_desc = |
| 808 | transport_info.description; |
| 809 | transport_desc.ice_ufrag = ufrag; |
| 810 | transport_desc.ice_pwd = pwd; |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 814 | // Sets ufrag/pwd for specified |media_type|. |
| 815 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 816 | cricket::MediaType media_type, |
| 817 | const std::string& ufrag, |
| 818 | const std::string& pwd) { |
| 819 | cricket::SessionDescription* desc = current_desc->description(); |
| 820 | const cricket::ContentInfo* cinfo = |
| 821 | cricket::GetFirstMediaContent(desc->contents(), media_type); |
| 822 | TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name); |
| 823 | cricket::TransportDescription* transport_desc = |
| 824 | &transport_info->description; |
| 825 | transport_desc->ice_ufrag = ufrag; |
| 826 | transport_desc->ice_pwd = pwd; |
| 827 | } |
| 828 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | // Creates a remote offer and and applies it as a remote description, |
| 830 | // creates a local answer and applies is as a local description. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 831 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 832 | // to decide which local and remote streams to create. |
| 833 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 834 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 835 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 836 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 837 | SetLocalDescriptionWithoutError(answer); |
| 838 | } |
| 839 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 840 | EXPECT_TRUE(session_->SetLocalDescription(desc, NULL)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 841 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 842 | } |
| 843 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 844 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 845 | SetLocalDescriptionWithoutError(desc); |
| 846 | EXPECT_EQ(expected_state, session_->state()); |
| 847 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 848 | void SetLocalDescriptionExpectError(const std::string& action, |
| 849 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 850 | SessionDescriptionInterface* desc) { |
| 851 | std::string error; |
| 852 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 853 | std::string sdp_type = "local "; |
| 854 | sdp_type.append(action); |
| 855 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 856 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 857 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 858 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 859 | SessionDescriptionInterface* desc) { |
| 860 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 861 | expected_error, desc); |
| 862 | } |
| 863 | void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, |
| 864 | SessionDescriptionInterface* desc) { |
| 865 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 866 | expected_error, desc); |
| 867 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 868 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 869 | EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL)); |
| 870 | } |
| 871 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 872 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | SetRemoteDescriptionWithoutError(desc); |
| 874 | EXPECT_EQ(expected_state, session_->state()); |
| 875 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 876 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 877 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 878 | SessionDescriptionInterface* desc) { |
| 879 | std::string error; |
| 880 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 881 | std::string sdp_type = "remote "; |
| 882 | sdp_type.append(action); |
| 883 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 884 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 885 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 886 | void SetRemoteDescriptionOfferExpectError( |
| 887 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 888 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 889 | expected_error, desc); |
| 890 | } |
| 891 | void SetRemoteDescriptionPranswerExpectError( |
| 892 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 893 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer, |
| 894 | expected_error, desc); |
| 895 | } |
| 896 | void SetRemoteDescriptionAnswerExpectError( |
| 897 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 898 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 899 | expected_error, desc); |
| 900 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | |
| 902 | void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer, |
| 903 | SessionDescriptionInterface** nocrypto_answer) { |
| 904 | // Create a SDP without Crypto. |
| 905 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 906 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 907 | options.bundle_enabled = true; |
| 908 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 909 | ASSERT_TRUE(*offer != NULL); |
| 910 | VerifyCryptoParams((*offer)->description()); |
| 911 | |
| 912 | *nocrypto_answer = CreateRemoteAnswer(*offer, options, |
| 913 | cricket::SEC_DISABLED); |
| 914 | EXPECT_TRUE(*nocrypto_answer != NULL); |
| 915 | } |
| 916 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 917 | void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer, |
| 918 | SessionDescriptionInterface** nodtls_answer) { |
| 919 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 920 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 921 | options.bundle_enabled = true; |
| 922 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 923 | rtc::scoped_ptr<SessionDescriptionInterface> temp_offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 924 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
| 925 | |
| 926 | *nodtls_answer = |
| 927 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
| 928 | EXPECT_TRUE(*nodtls_answer != NULL); |
| 929 | VerifyFingerprintStatus((*nodtls_answer)->description(), false); |
| 930 | VerifyCryptoParams((*nodtls_answer)->description()); |
| 931 | |
| 932 | SetFactoryDtlsSrtp(); |
| 933 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 934 | ASSERT_TRUE(*offer != NULL); |
| 935 | VerifyFingerprintStatus((*offer)->description(), true); |
| 936 | VerifyCryptoParams((*offer)->description()); |
| 937 | } |
| 938 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 939 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 940 | cricket::MediaSessionOptions options, |
| 941 | cricket::SecurePolicy secure_policy, |
| 942 | const std::string& session_version, |
| 943 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 944 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 945 | const cricket::SessionDescription* cricket_desc = NULL; |
| 946 | if (current_desc) { |
| 947 | cricket_desc = current_desc->description(); |
| 948 | session_id = current_desc->session_id(); |
| 949 | } |
| 950 | |
| 951 | desc_factory_->set_secure(secure_policy); |
| 952 | JsepSessionDescription* offer( |
| 953 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 954 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 955 | session_id, session_version)) { |
| 956 | delete offer; |
| 957 | offer = NULL; |
| 958 | } |
| 959 | return offer; |
| 960 | } |
| 961 | JsepSessionDescription* CreateRemoteOffer( |
| 962 | cricket::MediaSessionOptions options) { |
| 963 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 964 | kSessionVersion, NULL); |
| 965 | } |
| 966 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 967 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 968 | return CreateRemoteOfferWithVersion( |
| 969 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 970 | } |
| 971 | JsepSessionDescription* CreateRemoteOffer( |
| 972 | cricket::MediaSessionOptions options, |
| 973 | const SessionDescriptionInterface* current_desc) { |
| 974 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 975 | kSessionVersion, current_desc); |
| 976 | } |
| 977 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 978 | JsepSessionDescription* CreateRemoteOfferWithSctpPort( |
| 979 | const char* sctp_stream_name, int new_port, |
| 980 | cricket::MediaSessionOptions options) { |
| 981 | options.data_channel_type = cricket::DCT_SCTP; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 982 | options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel", |
| 983 | sctp_stream_name); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 984 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 985 | } |
| 986 | |
| 987 | // Takes ownership of offer_basis (and deletes it). |
| 988 | JsepSessionDescription* ChangeSDPSctpPort( |
| 989 | int new_port, webrtc::SessionDescriptionInterface *offer_basis) { |
| 990 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 991 | // SessionDescription from the mutated string. |
| 992 | const char* default_port_str = "5000"; |
| 993 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 994 | 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] | 995 | std::string offer_str; |
| 996 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 997 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 998 | new_port_str, strlen(new_port_str), |
| 999 | &offer_str); |
| 1000 | JsepSessionDescription* offer = new JsepSessionDescription( |
| 1001 | offer_basis->type()); |
| 1002 | delete offer_basis; |
| 1003 | offer->Initialize(offer_str, NULL); |
| 1004 | return offer; |
| 1005 | } |
| 1006 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1007 | // Create a remote offer. Call SendAudioVideoStreamX() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1008 | // before this function to decide which streams to create. |
| 1009 | JsepSessionDescription* CreateRemoteOffer() { |
| 1010 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1011 | GetOptionsForAnswer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1012 | return CreateRemoteOffer(options, session_->remote_description()); |
| 1013 | } |
| 1014 | |
| 1015 | JsepSessionDescription* CreateRemoteAnswer( |
| 1016 | const SessionDescriptionInterface* offer, |
| 1017 | cricket::MediaSessionOptions options, |
| 1018 | cricket::SecurePolicy policy) { |
| 1019 | desc_factory_->set_secure(policy); |
| 1020 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1021 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1022 | JsepSessionDescription* answer( |
| 1023 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 1024 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 1025 | options, NULL), |
| 1026 | session_id, kSessionVersion)) { |
| 1027 | delete answer; |
| 1028 | answer = NULL; |
| 1029 | } |
| 1030 | return answer; |
| 1031 | } |
| 1032 | |
| 1033 | JsepSessionDescription* CreateRemoteAnswer( |
| 1034 | const SessionDescriptionInterface* offer, |
| 1035 | cricket::MediaSessionOptions options) { |
| 1036 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 1037 | } |
| 1038 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1039 | // Creates an answer session description. |
| 1040 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1041 | // to decide which streams to create. |
| 1042 | JsepSessionDescription* CreateRemoteAnswer( |
| 1043 | const SessionDescriptionInterface* offer) { |
| 1044 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1045 | GetOptionsForAnswer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1046 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 1047 | } |
| 1048 | |
| 1049 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1050 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1051 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1052 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1053 | |
| 1054 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1055 | options.use_rtp_mux = bundle; |
| 1056 | |
| 1057 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1058 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1059 | // and answer. |
| 1060 | SetLocalDescriptionWithoutError(offer); |
| 1061 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1062 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1063 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1064 | std::string sdp; |
| 1065 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 1066 | |
| 1067 | size_t expected_candidate_num = 2; |
| 1068 | if (!rtcp_mux) { |
| 1069 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 1070 | // for rtp and rtcp. |
| 1071 | expected_candidate_num = 4; |
| 1072 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1073 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 1074 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1075 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1076 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 1077 | &sdp); |
| 1078 | } |
| 1079 | |
| 1080 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 1081 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1082 | |
| 1083 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1084 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1085 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1086 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1087 | if (bundle) { |
| 1088 | EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
| 1089 | } else { |
| 1090 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | // Tests that we can only send DTMF when the dtmf codec is supported. |
| 1094 | void TestCanInsertDtmf(bool can) { |
| 1095 | if (can) { |
| 1096 | InitWithDtmfCodec(); |
| 1097 | } else { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1098 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1099 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1100 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1101 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1102 | EXPECT_FALSE(session_->CanInsertDtmf("")); |
| 1103 | EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1)); |
| 1104 | } |
| 1105 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1106 | // Helper class to configure loopback network and verify Best |
| 1107 | // Connection using right IP protocol for TestLoopbackCall |
| 1108 | // method. LoopbackNetworkManager applies firewall rules to block |
| 1109 | // all ping traffic once ICE completed, and remove them to observe |
| 1110 | // ICE reconnected again. This LoopbackNetworkConfiguration struct |
| 1111 | // verifies the best connection is using the right IP protocol after |
| 1112 | // initial ICE convergences. |
| 1113 | |
| 1114 | class LoopbackNetworkConfiguration { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1115 | public: |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1116 | LoopbackNetworkConfiguration() |
| 1117 | : test_ipv6_network_(false), |
| 1118 | test_extra_ipv4_network_(false), |
| 1119 | best_connection_after_initial_ice_converged_(1, 0) {} |
| 1120 | |
| 1121 | // Used to track the expected best connection count in each IP protocol. |
| 1122 | struct ExpectedBestConnection { |
| 1123 | ExpectedBestConnection(int ipv4_count, int ipv6_count) |
| 1124 | : ipv4_count_(ipv4_count), |
| 1125 | ipv6_count_(ipv6_count) {} |
| 1126 | |
| 1127 | int ipv4_count_; |
| 1128 | int ipv6_count_; |
| 1129 | }; |
| 1130 | |
| 1131 | bool test_ipv6_network_; |
| 1132 | bool test_extra_ipv4_network_; |
| 1133 | ExpectedBestConnection best_connection_after_initial_ice_converged_; |
| 1134 | |
| 1135 | void VerifyBestConnectionAfterIceConverge( |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1136 | const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const { |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1137 | Verify(metrics_observer, best_connection_after_initial_ice_converged_); |
| 1138 | } |
| 1139 | |
| 1140 | private: |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1141 | void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer, |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1142 | const ExpectedBestConnection& expected) const { |
| 1143 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1144 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1145 | webrtc::kBestConnections_IPv4), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1146 | expected.ipv4_count_); |
| 1147 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1148 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1149 | webrtc::kBestConnections_IPv6), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1150 | expected.ipv6_count_); |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1151 | // This is used in the loopback call so there is only single host to host |
| 1152 | // candidate pair. |
| 1153 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1154 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1155 | webrtc::kIceCandidatePairHostHost), |
Guo-wei Shieh | 3cc834a | 2015-09-04 15:52:14 -0700 | [diff] [blame] | 1156 | 0); |
| 1157 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1158 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1159 | webrtc::kIceCandidatePairHostPublicHostPublic), |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1160 | 1); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1161 | } |
| 1162 | }; |
| 1163 | |
| 1164 | class LoopbackNetworkManager { |
| 1165 | public: |
| 1166 | LoopbackNetworkManager(WebRtcSessionTest* session, |
| 1167 | const LoopbackNetworkConfiguration& config) |
| 1168 | : config_(config) { |
| 1169 | session->AddInterface( |
| 1170 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1171 | if (config_.test_extra_ipv4_network_) { |
| 1172 | session->AddInterface( |
| 1173 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1174 | } |
| 1175 | if (config_.test_ipv6_network_) { |
| 1176 | session->AddInterface( |
| 1177 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | void ApplyFirewallRules(rtc::FirewallSocketServer* fss) { |
| 1182 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1183 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1184 | if (config_.test_extra_ipv4_network_) { |
| 1185 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1186 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1187 | } |
| 1188 | if (config_.test_ipv6_network_) { |
| 1189 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1190 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); } |
| 1195 | |
| 1196 | private: |
| 1197 | LoopbackNetworkConfiguration config_; |
| 1198 | }; |
| 1199 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1200 | // The method sets up a call from the session to itself, in a loopback |
| 1201 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1202 | // disconnection, and then a permanent disconnection. |
| 1203 | // 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] | 1204 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 1205 | // While running the call, this method also checks if the session goes through |
| 1206 | // the correct sequence of ICE states when a connection is established, |
| 1207 | // broken, and re-established. |
| 1208 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1209 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 1210 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1211 | // The Gathering state should go: New -> Gathering -> Completed. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1212 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1213 | void SetupLoopbackCall() { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1214 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1215 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1216 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1217 | |
| 1218 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 1219 | observer_.ice_gathering_state_); |
| 1220 | SetLocalDescriptionWithoutError(offer); |
| 1221 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 1222 | observer_.ice_connection_state_); |
| 1223 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1224 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1225 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1226 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1227 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1228 | |
| 1229 | std::string sdp; |
| 1230 | offer->ToString(&sdp); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1231 | SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( |
| 1232 | JsepSessionDescription::kAnswer, sdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1233 | ASSERT_TRUE(desc != NULL); |
| 1234 | SetRemoteDescriptionWithoutError(desc); |
| 1235 | |
| 1236 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1237 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1238 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1239 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 1240 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1241 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 1242 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1243 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1244 | void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { |
| 1245 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 1246 | SetupLoopbackCall(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1247 | config.VerifyBestConnectionAfterIceConverge(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1248 | // Adding firewall rule to block ping requests, which should cause |
| 1249 | // transport channel failure. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1250 | |
| 1251 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1252 | |
| 1253 | LOG(LS_INFO) << "Firewall Rules applied"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1254 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 1255 | observer_.ice_connection_state_, |
| 1256 | kIceCandidatesTimeout); |
| 1257 | |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1258 | metrics_observer_->Reset(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1259 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1260 | // Clearing the rules, session should move back to completed state. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1261 | loopback_network_manager.ClearRules(fss_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1262 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1263 | LOG(LS_INFO) << "Firewall Rules cleared"; |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1264 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1265 | observer_.ice_connection_state_, |
| 1266 | kIceCandidatesTimeout); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1267 | |
| 1268 | // Now we block ping requests and wait until the ICE connection transitions |
| 1269 | // to the Failed state. This will take at least 30 seconds because it must |
| 1270 | // wait for the Port to timeout. |
| 1271 | int port_timeout = 30000; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1272 | |
| 1273 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1274 | LOG(LS_INFO) << "Firewall Rules applied again"; |
jlmiller@webrtc.org | 804eb46 | 2015-02-20 02:20:03 +0000 | [diff] [blame] | 1275 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1276 | observer_.ice_connection_state_, |
| 1277 | kIceCandidatesTimeout + port_timeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1280 | void TestLoopbackCall() { |
| 1281 | LoopbackNetworkConfiguration config; |
| 1282 | TestLoopbackCall(config); |
| 1283 | } |
| 1284 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1285 | void TestPacketOptions() { |
| 1286 | media_controller_.reset( |
| 1287 | new cricket::FakeMediaController(channel_manager_.get(), &fake_call_)); |
| 1288 | LoopbackNetworkConfiguration config; |
| 1289 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 1290 | |
| 1291 | SetupLoopbackCall(); |
| 1292 | |
| 1293 | uint8_t test_packet[15] = {0}; |
| 1294 | rtc::PacketOptions options; |
| 1295 | options.packet_id = 10; |
| 1296 | media_engine_->GetVideoChannel(0) |
| 1297 | ->SendRtp(test_packet, sizeof(test_packet), options); |
| 1298 | |
| 1299 | const int kPacketTimeout = 2000; |
| 1300 | EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout); |
| 1301 | EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1); |
| 1302 | } |
| 1303 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1304 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 1305 | void AddCNCodecs() { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1306 | const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0); |
| 1307 | const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0); |
| 1308 | |
| 1309 | // Add kCNCodec for dtmf test. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1310 | std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();; |
| 1311 | codecs.push_back(kCNCodec1); |
| 1312 | codecs.push_back(kCNCodec2); |
| 1313 | media_engine_->SetAudioCodecs(codecs); |
| 1314 | desc_factory_->set_audio_codecs(codecs); |
| 1315 | } |
| 1316 | |
| 1317 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 1318 | const cricket::ContentDescription* description = content->description; |
| 1319 | ASSERT(description != NULL); |
| 1320 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1321 | static_cast<const cricket::AudioContentDescription*>(description); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1322 | ASSERT(audio_content_desc != NULL); |
| 1323 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 1324 | if (audio_content_desc->codecs()[i].name == "CN") |
| 1325 | return false; |
| 1326 | } |
| 1327 | return true; |
| 1328 | } |
| 1329 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1330 | void CreateDataChannel() { |
deadbeef | fc648b6 | 2015-10-13 16:42:33 -0700 | [diff] [blame] | 1331 | webrtc::InternalDataChannelInit dci; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1332 | ASSERT(session_.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1333 | dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP; |
| 1334 | data_channel_ = DataChannel::Create( |
| 1335 | session_.get(), session_->data_channel_type(), "datachannel", dci); |
| 1336 | } |
| 1337 | |
| 1338 | void SetLocalDescriptionWithDataChannel() { |
| 1339 | CreateDataChannel(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1340 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1341 | SetLocalDescriptionWithoutError(offer); |
| 1342 | } |
| 1343 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1344 | void VerifyMultipleAsyncCreateDescription( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1345 | RTCCertificateGenerationMethod cert_gen_method, |
| 1346 | CreateSessionDescriptionRequest::Type type) { |
| 1347 | InitWithDtls(cert_gen_method); |
| 1348 | VerifyMultipleAsyncCreateDescriptionAfterInit(true, type); |
| 1349 | } |
| 1350 | |
| 1351 | void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 1352 | CreateSessionDescriptionRequest::Type type) { |
| 1353 | InitWithDtlsIdentityGenFail(); |
| 1354 | VerifyMultipleAsyncCreateDescriptionAfterInit(false, type); |
| 1355 | } |
| 1356 | |
| 1357 | void VerifyMultipleAsyncCreateDescriptionAfterInit( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1358 | bool success, CreateSessionDescriptionRequest::Type type) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1359 | RTC_CHECK(session_); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1360 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1361 | if (type == CreateSessionDescriptionRequest::kAnswer) { |
| 1362 | cricket::MediaSessionOptions options; |
| 1363 | scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1364 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1365 | ASSERT_TRUE(offer.get() != NULL); |
| 1366 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1367 | } |
| 1368 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1369 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1370 | cricket::MediaSessionOptions session_options; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1371 | const int kNumber = 3; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1372 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1373 | observers[kNumber]; |
| 1374 | for (int i = 0; i < kNumber; ++i) { |
| 1375 | observers[i] = new WebRtcSessionCreateSDPObserverForTest(); |
| 1376 | if (type == CreateSessionDescriptionRequest::kOffer) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1377 | session_->CreateOffer(observers[i], options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1378 | } else { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1379 | session_->CreateAnswer(observers[i], session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | WebRtcSessionCreateSDPObserverForTest::State expected_state = |
| 1384 | success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded : |
| 1385 | WebRtcSessionCreateSDPObserverForTest::kFailed; |
| 1386 | |
| 1387 | for (int i = 0; i < kNumber; ++i) { |
| 1388 | EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000); |
| 1389 | if (success) { |
| 1390 | EXPECT_TRUE(observers[i]->description() != NULL); |
| 1391 | } else { |
| 1392 | EXPECT_TRUE(observers[i]->description() == NULL); |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1397 | void ConfigureAllocatorWithTurn() { |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1398 | cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1399 | cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1400 | turn_server.credentials = credentials; |
| 1401 | turn_server.ports.push_back( |
| 1402 | cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
| 1403 | allocator_->AddTurnServer(turn_server); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1404 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 1405 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1408 | cricket::FakeMediaEngine* media_engine_; |
| 1409 | cricket::FakeDataEngine* data_engine_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1410 | rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1411 | cricket::FakeCall fake_call_; |
| 1412 | rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1413 | rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1414 | rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
| 1415 | rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1416 | rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1417 | rtc::scoped_ptr<rtc::FirewallSocketServer> fss_; |
| 1418 | rtc::SocketServerScope ss_scope_; |
| 1419 | rtc::SocketAddress stun_socket_addr_; |
jiayl@webrtc.org | bebc75e | 2014-09-26 23:01:11 +0000 | [diff] [blame] | 1420 | rtc::scoped_ptr<cricket::TestStunServer> stun_server_; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1421 | cricket::TestTurnServer turn_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1422 | rtc::FakeNetworkManager network_manager_; |
| 1423 | rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1424 | PeerConnectionFactoryInterface::Options options_; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1425 | PeerConnectionInterface::RTCConfiguration configuration_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1426 | rtc::scoped_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1427 | MockIceObserver observer_; |
| 1428 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1429 | cricket::FakeVoiceMediaChannel* voice_channel_; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1430 | rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1431 | // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1432 | bool send_stream_1_ = false; |
| 1433 | bool send_stream_2_ = false; |
| 1434 | bool send_audio_ = false; |
| 1435 | bool send_video_ = false; |
| 1436 | rtc::scoped_refptr<DataChannel> data_channel_; |
| 1437 | // Last values received from data channel creation signal. |
| 1438 | std::string last_data_channel_label_; |
| 1439 | InternalDataChannelInit last_data_channel_config_; |
deadbeef | 8947a01 | 2016-01-21 10:26:38 -0800 | [diff] [blame] | 1440 | bool session_destroyed_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1441 | }; |
| 1442 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1443 | TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1444 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1445 | // SDES is disabled when DTLS is on. |
| 1446 | EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1449 | TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1450 | Init(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1451 | // SDES is required if DTLS is off. |
| 1452 | EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1455 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1456 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1457 | } |
| 1458 | |
| 1459 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1460 | // with rtcp-mux and/or bundle. |
| 1461 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1462 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1463 | } |
| 1464 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1465 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1466 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1467 | } |
| 1468 | |
| 1469 | TEST_F(WebRtcSessionTest, TestMultihomeCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1470 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1471 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1472 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1473 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1474 | InitiateCall(); |
| 1475 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1476 | EXPECT_EQ(8u, observer_.mline_0_candidates_.size()); |
| 1477 | EXPECT_EQ(8u, observer_.mline_1_candidates_.size()); |
| 1478 | } |
| 1479 | |
minyue | c8930ba | 2016-01-22 06:17:46 -0800 | [diff] [blame] | 1480 | // Crashes on Win only. See webrtc:5411. |
| 1481 | #if defined(WEBRTC_WIN) |
| 1482 | #define MAYBE_TestStunError DISABLED_TestStunError |
| 1483 | #else |
| 1484 | #define MAYBE_TestStunError TestStunError |
| 1485 | #endif |
| 1486 | TEST_F(WebRtcSessionTest, MAYBE_TestStunError) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1487 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1488 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1489 | fss_->AddRule(false, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1490 | rtc::FP_UDP, |
| 1491 | rtc::FD_ANY, |
| 1492 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1493 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1494 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1495 | InitiateCall(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1496 | // Since kClientAddrHost1 is blocked, not expecting stun candidates for it. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1497 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1498 | EXPECT_EQ(6u, observer_.mline_0_candidates_.size()); |
| 1499 | EXPECT_EQ(6u, observer_.mline_1_candidates_.size()); |
| 1500 | } |
| 1501 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1502 | // Test session delivers no candidates gathered when constraint set to "none". |
| 1503 | TEST_F(WebRtcSessionTest, TestIceTransportsNone) { |
| 1504 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1505 | InitWithIceTransport(PeerConnectionInterface::kNone); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1506 | SendAudioVideoStream1(); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1507 | InitiateCall(); |
| 1508 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1509 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 1510 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 1511 | } |
| 1512 | |
| 1513 | // Test session delivers only relay candidates gathered when constaint set to |
| 1514 | // "relay". |
| 1515 | TEST_F(WebRtcSessionTest, TestIceTransportsRelay) { |
| 1516 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1517 | ConfigureAllocatorWithTurn(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1518 | InitWithIceTransport(PeerConnectionInterface::kRelay); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1519 | SendAudioVideoStream1(); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1520 | InitiateCall(); |
| 1521 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1522 | EXPECT_EQ(2u, observer_.mline_0_candidates_.size()); |
| 1523 | EXPECT_EQ(2u, observer_.mline_1_candidates_.size()); |
| 1524 | for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) { |
| 1525 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 1526 | observer_.mline_0_candidates_[i].type()); |
| 1527 | } |
| 1528 | for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) { |
| 1529 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 1530 | observer_.mline_1_candidates_[i].type()); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | // Test session delivers all candidates gathered when constaint set to "all". |
| 1535 | TEST_F(WebRtcSessionTest, TestIceTransportsAll) { |
| 1536 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1537 | InitWithIceTransport(PeerConnectionInterface::kAll); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1538 | SendAudioVideoStream1(); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1539 | InitiateCall(); |
| 1540 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1541 | // Host + STUN. By default allocator is disabled to gather relay candidates. |
| 1542 | EXPECT_EQ(4u, observer_.mline_0_candidates_.size()); |
| 1543 | EXPECT_EQ(4u, observer_.mline_1_candidates_.size()); |
| 1544 | } |
| 1545 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1546 | TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1547 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1548 | SessionDescriptionInterface* offer = NULL; |
| 1549 | // Since |offer| is NULL, there's no way to tell if it's an offer or answer. |
| 1550 | std::string unknown_action; |
| 1551 | SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1552 | SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1553 | } |
| 1554 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1555 | // Test creating offers and receive answers and make sure the |
| 1556 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1557 | TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1558 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1559 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1560 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1561 | const std::string session_id_orig = offer->session_id(); |
| 1562 | const std::string session_version_orig = offer->session_version(); |
| 1563 | SetLocalDescriptionWithoutError(offer); |
| 1564 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1565 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1566 | SessionDescriptionInterface* answer = |
| 1567 | CreateRemoteAnswer(session_->local_description()); |
| 1568 | SetRemoteDescriptionWithoutError(answer); |
| 1569 | |
| 1570 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1571 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1572 | |
| 1573 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1574 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1575 | |
| 1576 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1577 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1578 | |
| 1579 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1580 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1581 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1582 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1583 | |
| 1584 | // Create new offer without send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1585 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1586 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1587 | |
| 1588 | // Verify the session id is the same and the session version is |
| 1589 | // increased. |
| 1590 | EXPECT_EQ(session_id_orig, offer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1591 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1592 | rtc::FromString<uint64_t>(offer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1593 | |
| 1594 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1595 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1596 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1597 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1598 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1599 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1600 | SetRemoteDescriptionWithoutError(answer); |
| 1601 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1602 | // Make sure the receive streams have not changed. |
| 1603 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1604 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1605 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1606 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1607 | } |
| 1608 | |
| 1609 | // Test receiving offers and creating answers and make sure the |
| 1610 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1611 | TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1612 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1613 | SendAudioVideoStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1614 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1615 | VerifyCryptoParams(offer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1616 | SetRemoteDescriptionWithoutError(offer); |
| 1617 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1618 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1619 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1620 | VerifyCryptoParams(answer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1621 | SetLocalDescriptionWithoutError(answer); |
| 1622 | |
| 1623 | const std::string session_id_orig = answer->session_id(); |
| 1624 | const std::string session_version_orig = answer->session_version(); |
| 1625 | |
| 1626 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1627 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1628 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1629 | ASSERT_TRUE(video_channel_); |
| 1630 | ASSERT_TRUE(voice_channel_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1631 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1632 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1633 | |
| 1634 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1635 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1636 | |
| 1637 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1638 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1639 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1640 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1641 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1642 | SendAudioVideoStream1And2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1643 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1644 | SetRemoteDescriptionWithoutError(offer); |
| 1645 | |
| 1646 | // Answer by turning off all send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1647 | SendNothing(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1648 | answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1649 | |
| 1650 | // Verify the session id is the same and the session version is |
| 1651 | // increased. |
| 1652 | EXPECT_EQ(session_id_orig, answer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1653 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1654 | rtc::FromString<uint64_t>(answer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1655 | SetLocalDescriptionWithoutError(answer); |
| 1656 | |
| 1657 | ASSERT_EQ(2u, video_channel_->recv_streams().size()); |
| 1658 | EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id); |
| 1659 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id); |
| 1660 | ASSERT_EQ(2u, voice_channel_->recv_streams().size()); |
| 1661 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id); |
| 1662 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id); |
| 1663 | |
| 1664 | // Make sure we have no send streams. |
| 1665 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1666 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1667 | } |
| 1668 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1669 | TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1670 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1671 | media_engine_->set_fail_create_channel(true); |
| 1672 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1673 | SessionDescriptionInterface* offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1674 | ASSERT_TRUE(offer != NULL); |
| 1675 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1676 | // the offer. |
| 1677 | SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1678 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1679 | ASSERT_TRUE(offer != NULL); |
| 1680 | SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer); |
| 1681 | } |
| 1682 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1683 | // |
| 1684 | // Tests for creating/setting SDP under different SDES/DTLS polices: |
| 1685 | // |
| 1686 | // --DTLS off and SDES on |
| 1687 | // TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer: |
| 1688 | // set local/remote offer/answer with crypto --> success |
| 1689 | // TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto ---> |
| 1690 | // failure |
| 1691 | // TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto --> |
| 1692 | // failure |
| 1693 | // TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto --> |
| 1694 | // failure |
| 1695 | // |
| 1696 | // --DTLS on and SDES off |
| 1697 | // TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer: |
| 1698 | // set local/remote offer/answer with DTLS fingerprint --> success |
| 1699 | // TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS |
| 1700 | // fingerprint --> failure |
| 1701 | // TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint |
| 1702 | // --> failure |
| 1703 | // TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint |
| 1704 | // --> failure |
| 1705 | // |
| 1706 | // --Encryption disabled: DTLS off and SDES off |
| 1707 | // TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote |
| 1708 | // answer without SDES or DTLS --> success |
| 1709 | // TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local |
| 1710 | // answer without SDES or DTLS --> success |
| 1711 | // |
| 1712 | |
| 1713 | // Test that we return a failure when applying a remote/local offer that doesn't |
| 1714 | // have cryptos enabled when DTLS is off. |
| 1715 | TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1716 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1717 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1718 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1719 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1720 | options, cricket::SEC_DISABLED); |
| 1721 | ASSERT_TRUE(offer != NULL); |
| 1722 | VerifyNoCryptoParams(offer->description(), false); |
| 1723 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1724 | // the offer. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1725 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1726 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1727 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1728 | SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1731 | // Test that we return a failure when applying a local answer that doesn't have |
| 1732 | // cryptos enabled when DTLS is off. |
| 1733 | TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1734 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1735 | SessionDescriptionInterface* offer = NULL; |
| 1736 | SessionDescriptionInterface* answer = NULL; |
| 1737 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1738 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1739 | // the offer. |
| 1740 | SetRemoteDescriptionWithoutError(offer); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1741 | SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1744 | // Test we will return fail when apply an remote answer that doesn't have |
| 1745 | // crypto enabled when DTLS is off. |
| 1746 | TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1747 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1748 | SessionDescriptionInterface* offer = NULL; |
| 1749 | SessionDescriptionInterface* answer = NULL; |
| 1750 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1751 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1752 | // the offer. |
| 1753 | SetLocalDescriptionWithoutError(offer); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1754 | SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1757 | // Test that we accept an offer with a DTLS fingerprint when DTLS is on |
| 1758 | // and that we return an answer with a DTLS fingerprint. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1759 | TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1760 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1761 | SendAudioVideoStream1(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1762 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1763 | SetFactoryDtlsSrtp(); |
| 1764 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1765 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1766 | JsepSessionDescription* offer = |
| 1767 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1768 | ASSERT_TRUE(offer != NULL); |
| 1769 | VerifyFingerprintStatus(offer->description(), true); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1770 | VerifyNoCryptoParams(offer->description(), true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1771 | |
| 1772 | // SetRemoteDescription will take the ownership of the offer. |
| 1773 | SetRemoteDescriptionWithoutError(offer); |
| 1774 | |
| 1775 | // Verify that we get a crypto fingerprint in the answer. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1776 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1777 | ASSERT_TRUE(answer != NULL); |
| 1778 | VerifyFingerprintStatus(answer->description(), true); |
| 1779 | // Check that we don't have an a=crypto line in the answer. |
| 1780 | VerifyNoCryptoParams(answer->description(), true); |
| 1781 | |
| 1782 | // Now set the local description, which should work, even without a=crypto. |
| 1783 | SetLocalDescriptionWithoutError(answer); |
| 1784 | } |
| 1785 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1786 | // Test that we set a local offer with a DTLS fingerprint when DTLS is on |
| 1787 | // and then we accept a remote answer with a DTLS fingerprint successfully. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1788 | TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1789 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1790 | SendAudioVideoStream1(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1791 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1792 | SetFactoryDtlsSrtp(); |
| 1793 | |
| 1794 | // Verify that we get a crypto fingerprint in the answer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1795 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1796 | ASSERT_TRUE(offer != NULL); |
| 1797 | VerifyFingerprintStatus(offer->description(), true); |
| 1798 | // Check that we don't have an a=crypto line in the offer. |
| 1799 | VerifyNoCryptoParams(offer->description(), true); |
| 1800 | |
| 1801 | // Now set the local description, which should work, even without a=crypto. |
| 1802 | SetLocalDescriptionWithoutError(offer); |
| 1803 | |
| 1804 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1805 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1806 | JsepSessionDescription* answer = |
| 1807 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1808 | ASSERT_TRUE(answer != NULL); |
| 1809 | VerifyFingerprintStatus(answer->description(), true); |
| 1810 | VerifyNoCryptoParams(answer->description(), true); |
| 1811 | |
| 1812 | // SetRemoteDescription will take the ownership of the answer. |
| 1813 | SetRemoteDescriptionWithoutError(answer); |
| 1814 | } |
| 1815 | |
| 1816 | // Test that if we support DTLS and the other side didn't offer a fingerprint, |
| 1817 | // we will fail to set the remote description. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1818 | TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1819 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1820 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1821 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1822 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1823 | options.bundle_enabled = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1824 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1825 | options, cricket::SEC_REQUIRED); |
| 1826 | ASSERT_TRUE(offer != NULL); |
| 1827 | VerifyFingerprintStatus(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1828 | VerifyCryptoParams(offer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1829 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1830 | // SetRemoteDescription will take the ownership of the offer. |
| 1831 | SetRemoteDescriptionOfferExpectError( |
| 1832 | kSdpWithoutDtlsFingerprint, offer); |
| 1833 | |
| 1834 | offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED); |
| 1835 | // SetLocalDescription will take the ownership of the offer. |
| 1836 | SetLocalDescriptionOfferExpectError( |
| 1837 | kSdpWithoutDtlsFingerprint, offer); |
| 1838 | } |
| 1839 | |
| 1840 | // Test that we return a failure when applying a local answer that doesn't have |
| 1841 | // a DTLS fingerprint when DTLS is required. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1842 | TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1843 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1844 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1845 | SessionDescriptionInterface* offer = NULL; |
| 1846 | SessionDescriptionInterface* answer = NULL; |
| 1847 | CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer); |
| 1848 | |
| 1849 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1850 | // the offer and answer. |
| 1851 | SetRemoteDescriptionWithoutError(offer); |
| 1852 | SetLocalDescriptionAnswerExpectError( |
| 1853 | kSdpWithoutDtlsFingerprint, answer); |
| 1854 | } |
| 1855 | |
| 1856 | // Test that we return a failure when applying a remote answer that doesn't have |
| 1857 | // a DTLS fingerprint when DTLS is required. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1858 | TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1859 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1860 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1861 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1862 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1863 | options.recv_video = true; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1864 | rtc::scoped_ptr<SessionDescriptionInterface> temp_offer( |
| 1865 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1866 | JsepSessionDescription* answer = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1867 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1868 | |
| 1869 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1870 | // the offer and answer. |
| 1871 | SetLocalDescriptionWithoutError(offer); |
| 1872 | SetRemoteDescriptionAnswerExpectError( |
| 1873 | kSdpWithoutDtlsFingerprint, answer); |
| 1874 | } |
| 1875 | |
| 1876 | // Test that we create a local offer without SDES or DTLS and accept a remote |
| 1877 | // answer without SDES or DTLS when encryption is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1878 | TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1879 | SendAudioVideoStream1(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1880 | options_.disable_encryption = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1881 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1882 | |
| 1883 | // Verify that we get a crypto fingerprint in the answer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1884 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1885 | ASSERT_TRUE(offer != NULL); |
| 1886 | VerifyFingerprintStatus(offer->description(), false); |
| 1887 | // Check that we don't have an a=crypto line in the offer. |
| 1888 | VerifyNoCryptoParams(offer->description(), false); |
| 1889 | |
| 1890 | // Now set the local description, which should work, even without a=crypto. |
| 1891 | SetLocalDescriptionWithoutError(offer); |
| 1892 | |
| 1893 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1894 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1895 | JsepSessionDescription* answer = |
| 1896 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1897 | ASSERT_TRUE(answer != NULL); |
| 1898 | VerifyFingerprintStatus(answer->description(), false); |
| 1899 | VerifyNoCryptoParams(answer->description(), false); |
| 1900 | |
| 1901 | // SetRemoteDescription will take the ownership of the answer. |
| 1902 | SetRemoteDescriptionWithoutError(answer); |
| 1903 | } |
| 1904 | |
| 1905 | // Test that we create a local answer without SDES or DTLS and accept a remote |
| 1906 | // offer without SDES or DTLS when encryption is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1907 | TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1908 | options_.disable_encryption = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1909 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1910 | |
| 1911 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1912 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1913 | JsepSessionDescription* offer = |
| 1914 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1915 | ASSERT_TRUE(offer != NULL); |
| 1916 | VerifyFingerprintStatus(offer->description(), false); |
| 1917 | VerifyNoCryptoParams(offer->description(), false); |
| 1918 | |
| 1919 | // SetRemoteDescription will take the ownership of the offer. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1920 | SetRemoteDescriptionWithoutError(offer); |
| 1921 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1922 | // Verify that we get a crypto fingerprint in the answer. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1923 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1924 | ASSERT_TRUE(answer != NULL); |
| 1925 | VerifyFingerprintStatus(answer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1926 | // Check that we don't have an a=crypto line in the answer. |
| 1927 | VerifyNoCryptoParams(answer->description(), false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1928 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1929 | // 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] | 1930 | SetLocalDescriptionWithoutError(answer); |
| 1931 | } |
| 1932 | |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1933 | // Test that we can create and set an answer correctly when different |
| 1934 | // SSL roles have been negotiated for different transports. |
| 1935 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525 |
| 1936 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) { |
| 1937 | SendAudioVideoStream1(); |
| 1938 | InitWithDtls(GetParam()); |
| 1939 | SetFactoryDtlsSrtp(); |
| 1940 | |
| 1941 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1942 | SetLocalDescriptionWithoutError(offer); |
| 1943 | |
| 1944 | cricket::MediaSessionOptions options; |
| 1945 | options.recv_video = true; |
| 1946 | |
| 1947 | // First, negotiate different SSL roles. |
| 1948 | SessionDescriptionInterface* answer = |
| 1949 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1950 | TransportInfo* audio_transport_info = |
| 1951 | answer->description()->GetTransportInfoByName("audio"); |
| 1952 | audio_transport_info->description.connection_role = |
| 1953 | cricket::CONNECTIONROLE_ACTIVE; |
| 1954 | TransportInfo* video_transport_info = |
| 1955 | answer->description()->GetTransportInfoByName("video"); |
| 1956 | video_transport_info->description.connection_role = |
| 1957 | cricket::CONNECTIONROLE_PASSIVE; |
| 1958 | SetRemoteDescriptionWithoutError(answer); |
| 1959 | |
| 1960 | // Now create an offer in the reverse direction, and ensure the initial |
| 1961 | // offerer responds with an answer with correct SSL roles. |
| 1962 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1963 | kSessionVersion, |
| 1964 | session_->remote_description()); |
| 1965 | SetRemoteDescriptionWithoutError(offer); |
| 1966 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1967 | answer = CreateAnswer(); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1968 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1969 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1970 | audio_transport_info->description.connection_role); |
| 1971 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1972 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 1973 | video_transport_info->description.connection_role); |
| 1974 | SetLocalDescriptionWithoutError(answer); |
| 1975 | |
| 1976 | // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of |
| 1977 | // audio is transferred over to video in the answer that completes the BUNDLE |
| 1978 | // negotiation. |
| 1979 | options.bundle_enabled = true; |
| 1980 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1981 | kSessionVersion, |
| 1982 | session_->remote_description()); |
| 1983 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1984 | answer = CreateAnswer(); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1985 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1986 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1987 | audio_transport_info->description.connection_role); |
| 1988 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1989 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1990 | video_transport_info->description.connection_role); |
| 1991 | SetLocalDescriptionWithoutError(answer); |
| 1992 | } |
| 1993 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1994 | TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1995 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1996 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1997 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1998 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1999 | SetLocalDescriptionWithoutError(offer); |
| 2000 | |
| 2001 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2002 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2003 | SetLocalDescriptionWithoutError(offer2); |
| 2004 | } |
| 2005 | |
| 2006 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2007 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2008 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2009 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2010 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2011 | SetRemoteDescriptionWithoutError(offer); |
| 2012 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2013 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2014 | SetRemoteDescriptionWithoutError(offer2); |
| 2015 | } |
| 2016 | |
| 2017 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2018 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2019 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2020 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2021 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2022 | offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2023 | SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER", |
| 2024 | offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2028 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2029 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2030 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2031 | SetRemoteDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2032 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2033 | SetLocalDescriptionOfferExpectError( |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2034 | "Called in wrong state: STATE_RECEIVEDOFFER", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2038 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2039 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2040 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2041 | SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2042 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2043 | JsepSessionDescription* pranswer = |
| 2044 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2045 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2046 | SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2047 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2048 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2049 | JsepSessionDescription* pranswer2 = |
| 2050 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2051 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 2052 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2053 | SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2054 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2055 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2056 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2057 | SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2061 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2062 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2063 | SessionDescriptionInterface* offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2064 | SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2065 | |
| 2066 | JsepSessionDescription* pranswer = |
| 2067 | CreateRemoteAnswer(session_->local_description()); |
| 2068 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 2069 | |
| 2070 | SetRemoteDescriptionExpectState(pranswer, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2071 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2072 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2073 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | JsepSessionDescription* pranswer2 = |
| 2075 | CreateRemoteAnswer(session_->local_description()); |
| 2076 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 2077 | |
| 2078 | SetRemoteDescriptionExpectState(pranswer2, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2079 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2080 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2081 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2082 | SessionDescriptionInterface* answer = |
| 2083 | CreateRemoteAnswer(session_->local_description()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2084 | SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2088 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2089 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2090 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2091 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2092 | SessionDescriptionInterface* answer = |
| 2093 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2094 | SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT", |
| 2095 | answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2099 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2100 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2101 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2102 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2103 | SessionDescriptionInterface* answer = |
| 2104 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2105 | SetRemoteDescriptionAnswerExpectError( |
| 2106 | "Called in wrong state: STATE_INIT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2110 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2111 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2112 | |
| 2113 | cricket::Candidate candidate; |
| 2114 | candidate.set_component(1); |
| 2115 | JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); |
| 2116 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2117 | // Fail since we have not set a remote description. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2118 | EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2119 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2120 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2121 | SetLocalDescriptionWithoutError(offer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2122 | |
| 2123 | // Fail since we have not set a remote description. |
| 2124 | EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2125 | |
| 2126 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2127 | session_->local_description()); |
| 2128 | SetRemoteDescriptionWithoutError(answer); |
| 2129 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2130 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2131 | candidate.set_component(2); |
| 2132 | JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); |
| 2133 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2134 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2135 | // Verifying the candidates are copied properly from internal vector. |
| 2136 | const SessionDescriptionInterface* remote_desc = |
| 2137 | session_->remote_description(); |
| 2138 | ASSERT_TRUE(remote_desc != NULL); |
| 2139 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2140 | const IceCandidateCollection* candidates = |
| 2141 | remote_desc->candidates(kMediaContentIndex0); |
| 2142 | ASSERT_EQ(2u, candidates->count()); |
| 2143 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2144 | EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); |
| 2145 | EXPECT_EQ(1, candidates->at(0)->candidate().component()); |
| 2146 | EXPECT_EQ(2, candidates->at(1)->candidate().component()); |
| 2147 | |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 2148 | // |ice_candidate3| is identical to |ice_candidate2|. It can be added |
| 2149 | // successfully, but the total count of candidates will not increase. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2150 | candidate.set_component(2); |
| 2151 | JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); |
| 2152 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 2153 | ASSERT_EQ(2u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2154 | |
| 2155 | JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); |
| 2156 | EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); |
| 2157 | } |
| 2158 | |
| 2159 | // Test that a remote candidate is added to the remote session description and |
| 2160 | // that it is retained if the remote session description is changed. |
| 2161 | TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2162 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2163 | cricket::Candidate candidate1; |
| 2164 | candidate1.set_component(1); |
| 2165 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2166 | candidate1); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2167 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2168 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2169 | |
| 2170 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2171 | const SessionDescriptionInterface* remote_desc = |
| 2172 | session_->remote_description(); |
| 2173 | ASSERT_TRUE(remote_desc != NULL); |
| 2174 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2175 | const IceCandidateCollection* candidates = |
| 2176 | remote_desc->candidates(kMediaContentIndex0); |
| 2177 | ASSERT_EQ(1u, candidates->count()); |
| 2178 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2179 | |
| 2180 | // Update the RemoteSessionDescription with a new session description and |
| 2181 | // a candidate and check that the new remote session description contains both |
| 2182 | // candidates. |
| 2183 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2184 | cricket::Candidate candidate2; |
| 2185 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2186 | candidate2); |
| 2187 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 2188 | SetRemoteDescriptionWithoutError(offer); |
| 2189 | |
| 2190 | remote_desc = session_->remote_description(); |
| 2191 | ASSERT_TRUE(remote_desc != NULL); |
| 2192 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2193 | candidates = remote_desc->candidates(kMediaContentIndex0); |
| 2194 | ASSERT_EQ(2u, candidates->count()); |
| 2195 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2196 | // Username and password have be updated with the TransportInfo of the |
| 2197 | // SessionDescription, won't be equal to the original one. |
| 2198 | candidate2.set_username(candidates->at(0)->candidate().username()); |
| 2199 | candidate2.set_password(candidates->at(0)->candidate().password()); |
| 2200 | EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate())); |
| 2201 | EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index()); |
| 2202 | // No need to verify the username and password. |
| 2203 | candidate1.set_username(candidates->at(1)->candidate().username()); |
| 2204 | candidate1.set_password(candidates->at(1)->candidate().password()); |
| 2205 | EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); |
| 2206 | |
| 2207 | // Test that the candidate is ignored if we can add the same candidate again. |
| 2208 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2209 | } |
| 2210 | |
| 2211 | // Test that local candidates are added to the local session description and |
| 2212 | // that they are retained if the local session description is changed. |
| 2213 | TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2214 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2215 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2216 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2217 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2218 | |
| 2219 | const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 2220 | const IceCandidateCollection* candidates = |
| 2221 | local_desc->candidates(kMediaContentIndex0); |
| 2222 | ASSERT_TRUE(candidates != NULL); |
| 2223 | EXPECT_EQ(0u, candidates->count()); |
| 2224 | |
| 2225 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 2226 | |
| 2227 | local_desc = session_->local_description(); |
| 2228 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2229 | ASSERT_TRUE(candidates != NULL); |
| 2230 | EXPECT_LT(0u, candidates->count()); |
| 2231 | candidates = local_desc->candidates(1); |
| 2232 | ASSERT_TRUE(candidates != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2233 | EXPECT_EQ(0u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2234 | |
| 2235 | // Update the session descriptions. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2236 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2237 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2238 | |
| 2239 | local_desc = session_->local_description(); |
| 2240 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2241 | ASSERT_TRUE(candidates != NULL); |
| 2242 | EXPECT_LT(0u, candidates->count()); |
| 2243 | candidates = local_desc->candidates(1); |
| 2244 | ASSERT_TRUE(candidates != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2245 | EXPECT_EQ(0u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | // Test that we can set a remote session description with remote candidates. |
| 2249 | TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2250 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2251 | |
| 2252 | cricket::Candidate candidate1; |
| 2253 | candidate1.set_component(1); |
| 2254 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2255 | candidate1); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2256 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2257 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2258 | |
| 2259 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2260 | SetRemoteDescriptionWithoutError(offer); |
| 2261 | |
| 2262 | const SessionDescriptionInterface* remote_desc = |
| 2263 | session_->remote_description(); |
| 2264 | ASSERT_TRUE(remote_desc != NULL); |
| 2265 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2266 | const IceCandidateCollection* candidates = |
| 2267 | remote_desc->candidates(kMediaContentIndex0); |
| 2268 | ASSERT_EQ(1u, candidates->count()); |
| 2269 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2270 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2271 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2272 | SetLocalDescriptionWithoutError(answer); |
| 2273 | } |
| 2274 | |
| 2275 | // Test that offers and answers contains ice candidates when Ice candidates have |
| 2276 | // been gathered. |
| 2277 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2278 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2279 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2280 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2281 | // Ice is started but candidates are not provided until SetLocalDescription |
| 2282 | // is called. |
| 2283 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 2284 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 2285 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2286 | // Wait until at least one local candidate has been collected. |
| 2287 | EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(), |
| 2288 | kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2289 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2290 | rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer()); |
| 2291 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2292 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL); |
| 2293 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2294 | |
| 2295 | SessionDescriptionInterface* remote_offer(CreateRemoteOffer()); |
| 2296 | SetRemoteDescriptionWithoutError(remote_offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2297 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2298 | ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL); |
| 2299 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2300 | SetLocalDescriptionWithoutError(answer); |
| 2301 | } |
| 2302 | |
| 2303 | // Verifies TransportProxy and media channels are created with content names |
| 2304 | // present in the SessionDescription. |
| 2305 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2306 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2307 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2308 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2309 | |
| 2310 | // CreateOffer creates session description with the content names "audio" and |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2311 | // "video". Goal is to modify these content names and verify transport |
| 2312 | // channels |
| 2313 | // in the WebRtcSession, as channels are created with the content names |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2314 | // present in SDP. |
| 2315 | std::string sdp; |
| 2316 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 2317 | const std::string kAudioMid = "a=mid:audio"; |
| 2318 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 2319 | const std::string kVideoMid = "a=mid:video"; |
| 2320 | const std::string kVideoMidReplaceStr = "a=mid:video_content_name"; |
| 2321 | |
| 2322 | // Replacing |audio| with |audio_content_name|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2323 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2324 | kAudioMidReplaceStr.c_str(), |
| 2325 | kAudioMidReplaceStr.length(), |
| 2326 | &sdp); |
| 2327 | // Replacing |video| with |video_content_name|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2328 | rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2329 | kVideoMidReplaceStr.c_str(), |
| 2330 | kVideoMidReplaceStr.length(), |
| 2331 | &sdp); |
| 2332 | |
| 2333 | SessionDescriptionInterface* modified_offer = |
| 2334 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2335 | |
| 2336 | SetRemoteDescriptionWithoutError(modified_offer); |
| 2337 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2338 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2339 | SetLocalDescriptionWithoutError(answer); |
| 2340 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2341 | cricket::TransportChannel* voice_transport_channel = |
| 2342 | session_->voice_rtp_transport_channel(); |
| 2343 | EXPECT_TRUE(voice_transport_channel != NULL); |
| 2344 | EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name"); |
| 2345 | cricket::TransportChannel* video_transport_channel = |
| 2346 | session_->video_rtp_transport_channel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2347 | ASSERT_TRUE(video_transport_channel != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2348 | EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2349 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 2350 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 2351 | } |
| 2352 | |
| 2353 | // Test that an offer contains the correct media content descriptions based on |
| 2354 | // the send streams when no constraints have been set. |
| 2355 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2356 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2357 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2358 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2359 | ASSERT_TRUE(offer != NULL); |
| 2360 | const cricket::ContentInfo* content = |
| 2361 | cricket::GetFirstAudioContent(offer->description()); |
| 2362 | EXPECT_TRUE(content != NULL); |
| 2363 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2364 | EXPECT_TRUE(content == NULL); |
| 2365 | } |
| 2366 | |
| 2367 | // Test that an offer contains the correct media content descriptions based on |
| 2368 | // the send streams when no constraints have been set. |
| 2369 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2370 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2371 | // Test Audio only offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2372 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2373 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2374 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2375 | const cricket::ContentInfo* content = |
| 2376 | cricket::GetFirstAudioContent(offer->description()); |
| 2377 | EXPECT_TRUE(content != NULL); |
| 2378 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2379 | EXPECT_TRUE(content == NULL); |
| 2380 | |
| 2381 | // Test Audio / Video offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2382 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2383 | offer.reset(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2384 | content = cricket::GetFirstAudioContent(offer->description()); |
| 2385 | EXPECT_TRUE(content != NULL); |
| 2386 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2387 | EXPECT_TRUE(content != NULL); |
| 2388 | } |
| 2389 | |
| 2390 | // Test that an offer contains no media content descriptions if |
| 2391 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 2392 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2393 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2394 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2395 | options.offer_to_receive_audio = 0; |
| 2396 | options.offer_to_receive_video = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2397 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2398 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2399 | CreateOffer(options)); |
| 2400 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2401 | ASSERT_TRUE(offer != NULL); |
| 2402 | const cricket::ContentInfo* content = |
| 2403 | cricket::GetFirstAudioContent(offer->description()); |
| 2404 | EXPECT_TRUE(content == NULL); |
| 2405 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2406 | EXPECT_TRUE(content == NULL); |
| 2407 | } |
| 2408 | |
| 2409 | // Test that an offer contains only audio media content descriptions if |
| 2410 | // kOfferToReceiveAudio constraints are set to true. |
| 2411 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2412 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2413 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2414 | options.offer_to_receive_audio = |
| 2415 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2416 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2417 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2418 | CreateOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2419 | |
| 2420 | const cricket::ContentInfo* content = |
| 2421 | cricket::GetFirstAudioContent(offer->description()); |
| 2422 | EXPECT_TRUE(content != NULL); |
| 2423 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2424 | EXPECT_TRUE(content == NULL); |
| 2425 | } |
| 2426 | |
| 2427 | // Test that an offer contains audio and video media content descriptions if |
| 2428 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 2429 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2430 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2431 | // Test Audio / Video offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2432 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2433 | options.offer_to_receive_audio = |
| 2434 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2435 | options.offer_to_receive_video = |
| 2436 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2437 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2438 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2439 | CreateOffer(options)); |
| 2440 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2441 | const cricket::ContentInfo* content = |
| 2442 | cricket::GetFirstAudioContent(offer->description()); |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2443 | EXPECT_TRUE(content != NULL); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2444 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2445 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2446 | EXPECT_TRUE(content != NULL); |
| 2447 | |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2448 | // Sets constraints to false and verifies that audio/video contents are |
| 2449 | // removed. |
| 2450 | options.offer_to_receive_audio = 0; |
| 2451 | options.offer_to_receive_video = 0; |
| 2452 | offer.reset(CreateOffer(options)); |
| 2453 | |
| 2454 | content = cricket::GetFirstAudioContent(offer->description()); |
| 2455 | EXPECT_TRUE(content == NULL); |
| 2456 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2457 | EXPECT_TRUE(content == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | // Test that an answer can not be created if the last remote description is not |
| 2461 | // an offer. |
| 2462 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2463 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2464 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2465 | SetLocalDescriptionWithoutError(offer); |
| 2466 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2467 | SetRemoteDescriptionWithoutError(answer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2468 | EXPECT_TRUE(CreateAnswer() == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | // Test that an answer contains the correct media content descriptions when no |
| 2472 | // constraints have been set. |
| 2473 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2474 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2475 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2476 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2477 | SetRemoteDescriptionWithoutError(offer.release()); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2478 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2479 | const cricket::ContentInfo* content = |
| 2480 | cricket::GetFirstAudioContent(answer->description()); |
| 2481 | ASSERT_TRUE(content != NULL); |
| 2482 | EXPECT_FALSE(content->rejected); |
| 2483 | |
| 2484 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2485 | ASSERT_TRUE(content != NULL); |
| 2486 | EXPECT_FALSE(content->rejected); |
| 2487 | } |
| 2488 | |
| 2489 | // Test that an answer contains the correct media content descriptions when no |
| 2490 | // constraints have been set and the offer only contain audio. |
| 2491 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2492 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2493 | // Create a remote offer with audio only. |
| 2494 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2495 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2496 | rtc::scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2497 | CreateRemoteOffer(options)); |
| 2498 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 2499 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 2500 | |
| 2501 | SetRemoteDescriptionWithoutError(offer.release()); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2502 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2503 | const cricket::ContentInfo* content = |
| 2504 | cricket::GetFirstAudioContent(answer->description()); |
| 2505 | ASSERT_TRUE(content != NULL); |
| 2506 | EXPECT_FALSE(content->rejected); |
| 2507 | |
| 2508 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 2509 | } |
| 2510 | |
| 2511 | // Test that an answer contains the correct media content descriptions when no |
| 2512 | // constraints have been set. |
| 2513 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2514 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2515 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2516 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2517 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2518 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2519 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2520 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2521 | const cricket::ContentInfo* content = |
| 2522 | cricket::GetFirstAudioContent(answer->description()); |
| 2523 | ASSERT_TRUE(content != NULL); |
| 2524 | EXPECT_FALSE(content->rejected); |
| 2525 | |
| 2526 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2527 | ASSERT_TRUE(content != NULL); |
| 2528 | EXPECT_FALSE(content->rejected); |
| 2529 | } |
| 2530 | |
| 2531 | // Test that an answer contains the correct media content descriptions when |
| 2532 | // constraints have been set but no stream is sent. |
| 2533 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2534 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2535 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2536 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2537 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2538 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2539 | cricket::MediaSessionOptions session_options; |
| 2540 | session_options.recv_audio = false; |
| 2541 | session_options.recv_video = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2542 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2543 | CreateAnswer(session_options)); |
| 2544 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2545 | const cricket::ContentInfo* content = |
| 2546 | cricket::GetFirstAudioContent(answer->description()); |
| 2547 | ASSERT_TRUE(content != NULL); |
| 2548 | EXPECT_TRUE(content->rejected); |
| 2549 | |
| 2550 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2551 | ASSERT_TRUE(content != NULL); |
| 2552 | EXPECT_TRUE(content->rejected); |
| 2553 | } |
| 2554 | |
| 2555 | // Test that an answer contains the correct media content descriptions when |
| 2556 | // constraints have been set and streams are sent. |
| 2557 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2558 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2559 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2560 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2561 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2562 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2563 | cricket::MediaSessionOptions options; |
| 2564 | options.recv_audio = false; |
| 2565 | options.recv_video = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2566 | |
| 2567 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2568 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2569 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2570 | |
| 2571 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2572 | const cricket::ContentInfo* content = |
| 2573 | cricket::GetFirstAudioContent(answer->description()); |
| 2574 | ASSERT_TRUE(content != NULL); |
| 2575 | EXPECT_FALSE(content->rejected); |
| 2576 | |
| 2577 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2578 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2579 | ASSERT_TRUE(content != NULL); |
| 2580 | EXPECT_FALSE(content->rejected); |
| 2581 | } |
| 2582 | |
| 2583 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 2584 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2585 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2586 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2587 | options.offer_to_receive_audio = |
| 2588 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2589 | options.voice_activity_detection = false; |
| 2590 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2591 | rtc::scoped_ptr<SessionDescriptionInterface> offer( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2592 | CreateOffer(options)); |
| 2593 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2594 | const cricket::ContentInfo* content = |
| 2595 | cricket::GetFirstAudioContent(offer->description()); |
| 2596 | EXPECT_TRUE(content != NULL); |
| 2597 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2598 | } |
| 2599 | |
| 2600 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 2601 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2602 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2603 | // Create a remote offer with audio and video content. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2604 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2605 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2606 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2607 | cricket::MediaSessionOptions options; |
| 2608 | options.vad_enabled = false; |
| 2609 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2610 | const cricket::ContentInfo* content = |
| 2611 | cricket::GetFirstAudioContent(answer->description()); |
| 2612 | ASSERT_TRUE(content != NULL); |
| 2613 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2614 | } |
| 2615 | |
| 2616 | // This test verifies the call setup when remote answer with audio only and |
| 2617 | // later updates with video. |
| 2618 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2619 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2620 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2621 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2622 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2623 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2624 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2625 | |
| 2626 | cricket::MediaSessionOptions options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2627 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 2628 | |
| 2629 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2630 | // and answer; |
| 2631 | SetLocalDescriptionWithoutError(offer); |
| 2632 | SetRemoteDescriptionWithoutError(answer); |
| 2633 | |
| 2634 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2635 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2636 | |
| 2637 | ASSERT_TRUE(video_channel_ == NULL); |
| 2638 | |
| 2639 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 2640 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2641 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 2642 | |
| 2643 | // Let the remote end update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2644 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2645 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2646 | |
| 2647 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2648 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2649 | |
| 2650 | ASSERT_TRUE(video_channel_ != NULL); |
| 2651 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2652 | |
| 2653 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2654 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2655 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2656 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2657 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2658 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2659 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2660 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2661 | |
| 2662 | // Change session back to audio only. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2663 | SendAudioOnlyStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2664 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2665 | |
| 2666 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2667 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2668 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2669 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2670 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2671 | } |
| 2672 | |
| 2673 | // This test verifies the call setup when remote answer with video only and |
| 2674 | // later updates with audio. |
| 2675 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2676 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2677 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2678 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2679 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2680 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2681 | |
| 2682 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 2683 | options.recv_audio = false; |
| 2684 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2685 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2686 | offer, options, cricket::SEC_ENABLED); |
| 2687 | |
| 2688 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2689 | // and answer. |
| 2690 | SetLocalDescriptionWithoutError(offer); |
| 2691 | SetRemoteDescriptionWithoutError(answer); |
| 2692 | |
| 2693 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2694 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2695 | |
| 2696 | ASSERT_TRUE(voice_channel_ == NULL); |
| 2697 | ASSERT_TRUE(video_channel_ != NULL); |
| 2698 | |
| 2699 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2700 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2701 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 2702 | |
| 2703 | // Update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2704 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2705 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2706 | |
| 2707 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2708 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2709 | |
| 2710 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2711 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2712 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2713 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2714 | |
| 2715 | // Change session back to video only. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2716 | SendVideoOnlyStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2717 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2718 | |
| 2719 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2720 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2721 | |
| 2722 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2723 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2724 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2725 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2726 | } |
| 2727 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2728 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2729 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2730 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2731 | scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2732 | VerifyCryptoParams(offer->description()); |
| 2733 | SetRemoteDescriptionWithoutError(offer.release()); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2734 | scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2735 | VerifyCryptoParams(answer->description()); |
| 2736 | } |
| 2737 | |
| 2738 | TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2739 | options_.disable_encryption = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2740 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2741 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2742 | scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2743 | VerifyNoCryptoParams(offer->description(), false); |
| 2744 | } |
| 2745 | |
| 2746 | TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2747 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2748 | VerifyAnswerFromNonCryptoOffer(); |
| 2749 | } |
| 2750 | |
| 2751 | TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2752 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2753 | VerifyAnswerFromCryptoOffer(); |
| 2754 | } |
| 2755 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2756 | // This test verifies that setLocalDescription fails if |
| 2757 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2758 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2759 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2760 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2761 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2762 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2763 | std::string sdp; |
| 2764 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2765 | SessionDescriptionInterface* modified_offer = |
| 2766 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2767 | SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | // This test verifies that setRemoteDescription fails if |
| 2771 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2772 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2773 | Init(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2774 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2775 | std::string sdp; |
| 2776 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2777 | SessionDescriptionInterface* modified_offer = |
| 2778 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2779 | SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2782 | // This test verifies that setLocalDescription fails if local offer has |
| 2783 | // too short ice ufrag and pwd strings. |
| 2784 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2785 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2786 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2787 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2788 | // Modifying ice ufrag and pwd in local offer with strings smaller than the |
| 2789 | // recommended values of 4 and 22 bytes respectively. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2790 | SetIceUfragPwd(offer.get(), "ice", "icepwd"); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2791 | std::string error; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2792 | EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2793 | |
| 2794 | // Test with string greater than 256. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2795 | offer.reset(CreateOffer()); |
| 2796 | SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd); |
| 2797 | EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | // This test verifies that setRemoteDescription fails if remote offer has |
| 2801 | // too short ice ufrag and pwd strings. |
| 2802 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2803 | Init(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2804 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2805 | // Modifying ice ufrag and pwd in remote offer with strings smaller than the |
| 2806 | // recommended values of 4 and 22 bytes respectively. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2807 | SetIceUfragPwd(offer.get(), "ice", "icepwd"); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2808 | std::string error; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2809 | EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2810 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2811 | offer.reset(CreateRemoteOffer()); |
| 2812 | SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd); |
| 2813 | EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2816 | // Test that if the remote offer indicates the peer requested ICE restart (via |
| 2817 | // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa. |
| 2818 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) { |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2819 | Init(); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2820 | |
| 2821 | // Create the first offer. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2822 | scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 2823 | SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2824 | cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), |
| 2825 | 0, "", "", "relay", 0, ""); |
| 2826 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2827 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2828 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 2829 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2830 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2831 | |
| 2832 | // The second offer has the same ufrag and pwd but different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2833 | offer.reset(CreateRemoteOffer()); |
| 2834 | SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2835 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2836 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2837 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2838 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 2839 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2840 | EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); |
| 2841 | |
| 2842 | // The third offer has a different ufrag and different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2843 | offer.reset(CreateRemoteOffer()); |
| 2844 | SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx"); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2845 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); |
| 2846 | JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, |
| 2847 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2848 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate3)); |
| 2849 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2850 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2851 | |
| 2852 | // The fourth offer has no candidate but a different ufrag/pwd. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2853 | offer.reset(CreateRemoteOffer()); |
| 2854 | SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz"); |
| 2855 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2856 | EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); |
| 2857 | } |
| 2858 | |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2859 | // Test that if the remote answer indicates the peer requested ICE restart (via |
| 2860 | // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa. |
| 2861 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) { |
| 2862 | Init(); |
| 2863 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2864 | SetLocalDescriptionWithoutError(offer); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2865 | |
| 2866 | // Create the first answer. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2867 | scoped_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer)); |
| 2868 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 2869 | SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2870 | cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), |
| 2871 | 0, "", "", "relay", 0, ""); |
| 2872 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2873 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2874 | EXPECT_TRUE(answer->AddCandidate(&ice_candidate1)); |
| 2875 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2876 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2877 | |
| 2878 | // The second answer has the same ufrag and pwd but different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2879 | answer.reset(CreateRemoteAnswer(offer)); |
| 2880 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 2881 | SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2882 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2883 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2884 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2885 | EXPECT_TRUE(answer->AddCandidate(&ice_candidate2)); |
| 2886 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2887 | EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); |
| 2888 | |
| 2889 | // The third answer has a different ufrag and different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2890 | answer.reset(CreateRemoteAnswer(offer)); |
| 2891 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 2892 | SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx"); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2893 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); |
| 2894 | JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, |
| 2895 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2896 | EXPECT_TRUE(answer->AddCandidate(&ice_candidate3)); |
| 2897 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2898 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2899 | |
| 2900 | // The fourth answer has no candidate but a different ufrag/pwd. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2901 | answer.reset(CreateRemoteAnswer(offer)); |
| 2902 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 2903 | SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz"); |
| 2904 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2905 | EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); |
| 2906 | } |
| 2907 | |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2908 | // Test that candidates sent to the "video" transport do not get pushed down to |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2909 | // the "audio" transport channel when bundling. |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2910 | TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { |
| 2911 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2912 | |
| 2913 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2914 | SendAudioVideoStream1(); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2915 | |
| 2916 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2917 | options.use_rtp_mux = true; |
| 2918 | |
| 2919 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2920 | SetRemoteDescriptionWithoutError(offer); |
| 2921 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2922 | SessionDescriptionInterface* answer = CreateAnswer(); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2923 | SetLocalDescriptionWithoutError(answer); |
| 2924 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2925 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2926 | session_->video_rtp_transport_channel()); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2927 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2928 | cricket::BaseChannel* voice_channel = session_->voice_channel(); |
| 2929 | ASSERT(voice_channel != NULL); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2930 | |
| 2931 | // Checks if one of the transport channels contains a connection using a given |
| 2932 | // port. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2933 | auto connection_with_remote_port = [this, voice_channel](int port) { |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2934 | SessionStats stats; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2935 | session_->GetChannelTransportStats(voice_channel, &stats); |
| 2936 | for (auto& kv : stats.transport_stats) { |
| 2937 | for (auto& chan_stat : kv.second.channel_stats) { |
| 2938 | for (auto& conn_info : chan_stat.connection_infos) { |
| 2939 | if (conn_info.remote_candidate.address().port() == port) { |
| 2940 | return true; |
| 2941 | } |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | } |
| 2945 | return false; |
| 2946 | }; |
| 2947 | |
| 2948 | EXPECT_FALSE(connection_with_remote_port(5000)); |
| 2949 | EXPECT_FALSE(connection_with_remote_port(5001)); |
| 2950 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2951 | |
| 2952 | // The way the *_WAIT checks work is they only wait if the condition fails, |
| 2953 | // which does not help in the case where state is not changing. This is |
| 2954 | // problematic in this test since we want to verify that adding a video |
| 2955 | // candidate does _not_ change state. So we interleave candidates and assume |
| 2956 | // that messages are executed in the order they were posted. |
| 2957 | |
| 2958 | // First audio candidate. |
| 2959 | cricket::Candidate candidate0; |
| 2960 | candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
| 2961 | candidate0.set_component(1); |
| 2962 | candidate0.set_protocol("udp"); |
| 2963 | JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0, |
| 2964 | candidate0); |
| 2965 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0)); |
| 2966 | |
| 2967 | // Video candidate. |
| 2968 | cricket::Candidate candidate1; |
| 2969 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2970 | candidate1.set_component(1); |
| 2971 | candidate1.set_protocol("udp"); |
| 2972 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2973 | candidate1); |
| 2974 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2975 | |
| 2976 | // Second audio candidate. |
| 2977 | cricket::Candidate candidate2; |
| 2978 | candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001)); |
| 2979 | candidate2.set_component(1); |
| 2980 | candidate2.set_protocol("udp"); |
| 2981 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2982 | candidate2); |
| 2983 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2984 | |
| 2985 | EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000); |
| 2986 | EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000); |
| 2987 | |
| 2988 | // No need here for a _WAIT check since we are checking that state hasn't |
| 2989 | // changed: if this is false we would be doing waits for nothing and if this |
| 2990 | // is true then there will be no messages processed anyways. |
| 2991 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2992 | } |
| 2993 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2994 | // kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2995 | TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) { |
| 2996 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2997 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2998 | |
| 2999 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3000 | options.use_rtp_mux = true; |
| 3001 | |
| 3002 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3003 | SetLocalDescriptionWithoutError(offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3004 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3005 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3006 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3007 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3008 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3009 | SessionDescriptionInterface* answer = |
| 3010 | CreateRemoteAnswer(session_->local_description()); |
| 3011 | SetRemoteDescriptionWithoutError(answer); |
| 3012 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3013 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3014 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3017 | // kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3018 | TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) { |
| 3019 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3020 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3021 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3022 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3023 | options.use_rtp_mux = true; |
| 3024 | |
| 3025 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3026 | SetLocalDescriptionWithoutError(offer); |
| 3027 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3028 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3029 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3030 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3031 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3032 | |
| 3033 | // Remove BUNDLE from the answer. |
| 3034 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
| 3035 | CreateRemoteAnswer(session_->local_description())); |
| 3036 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3037 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3038 | JsepSessionDescription* modified_answer = |
| 3039 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3040 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3041 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 3042 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3043 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3044 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer. |
| 3048 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) { |
| 3049 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3050 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3051 | |
| 3052 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3053 | options.use_rtp_mux = true; |
| 3054 | |
| 3055 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3056 | SetLocalDescriptionWithoutError(offer); |
| 3057 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3058 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3059 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3060 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3061 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3062 | SessionDescriptionInterface* answer = |
| 3063 | CreateRemoteAnswer(session_->local_description()); |
| 3064 | SetRemoteDescriptionWithoutError(answer); |
| 3065 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3066 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3067 | session_->video_rtp_transport_channel()); |
| 3068 | } |
| 3069 | |
| 3070 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no |
| 3071 | // audio content in the answer. |
| 3072 | TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) { |
| 3073 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3074 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3075 | |
| 3076 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3077 | options.use_rtp_mux = true; |
| 3078 | |
| 3079 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3080 | SetLocalDescriptionWithoutError(offer); |
| 3081 | |
| 3082 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3083 | session_->video_rtp_transport_channel()); |
| 3084 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3085 | SendAudioVideoStream2(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3086 | cricket::MediaSessionOptions recv_options; |
| 3087 | recv_options.recv_audio = false; |
| 3088 | recv_options.recv_video = true; |
| 3089 | SessionDescriptionInterface* answer = |
| 3090 | CreateRemoteAnswer(session_->local_description(), recv_options); |
| 3091 | SetRemoteDescriptionWithoutError(answer); |
| 3092 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3093 | EXPECT_TRUE(nullptr == session_->voice_channel()); |
| 3094 | EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3095 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3096 | session_->Close(); |
| 3097 | EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel()); |
| 3098 | EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel()); |
| 3099 | EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel()); |
| 3100 | EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | // kBundlePolicyMaxBundle policy but no BUNDLE in the answer. |
| 3104 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) { |
| 3105 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3106 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3107 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3108 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3109 | options.use_rtp_mux = true; |
| 3110 | |
| 3111 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3112 | SetLocalDescriptionWithoutError(offer); |
| 3113 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3114 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3115 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3116 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3117 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3118 | |
| 3119 | // Remove BUNDLE from the answer. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3120 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3121 | CreateRemoteAnswer(session_->local_description())); |
| 3122 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3123 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3124 | JsepSessionDescription* modified_answer = |
| 3125 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3126 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3127 | SetRemoteDescriptionWithoutError(modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3128 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3129 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3130 | session_->video_rtp_transport_channel()); |
| 3131 | } |
| 3132 | |
| 3133 | // kBundlePolicyMaxBundle policy with BUNDLE in the remote offer. |
| 3134 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) { |
| 3135 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3136 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3137 | |
| 3138 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3139 | SetRemoteDescriptionWithoutError(offer); |
| 3140 | |
| 3141 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3142 | session_->video_rtp_transport_channel()); |
| 3143 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3144 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3145 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3146 | SetLocalDescriptionWithoutError(answer); |
| 3147 | |
| 3148 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3149 | session_->video_rtp_transport_channel()); |
| 3150 | } |
| 3151 | |
| 3152 | // kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer. |
| 3153 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) { |
| 3154 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3155 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3156 | |
| 3157 | // Remove BUNDLE from the offer. |
| 3158 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 3159 | cricket::SessionDescription* offer_copy = offer->description()->Copy(); |
| 3160 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3161 | JsepSessionDescription* modified_offer = |
| 3162 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3163 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 3164 | |
| 3165 | // Expect an error when applying the remote description |
| 3166 | SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, |
| 3167 | kCreateChannelFailed, modified_offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3168 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3169 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3170 | // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3171 | TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { |
| 3172 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3173 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3174 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3175 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3176 | options.use_rtp_mux = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3177 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3178 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3179 | SetLocalDescriptionWithoutError(offer); |
| 3180 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3181 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3182 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3183 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3184 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3185 | SessionDescriptionInterface* answer = |
| 3186 | CreateRemoteAnswer(session_->local_description()); |
| 3187 | SetRemoteDescriptionWithoutError(answer); |
| 3188 | |
| 3189 | // This should lead to an audio-only call but isn't implemented |
| 3190 | // correctly yet. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3191 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3192 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3195 | // kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3196 | TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) { |
| 3197 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3198 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3199 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3200 | options.use_rtp_mux = true; |
| 3201 | |
| 3202 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3203 | SetLocalDescriptionWithoutError(offer); |
| 3204 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3205 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3206 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3207 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3208 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3209 | |
| 3210 | // Remove BUNDLE from the answer. |
| 3211 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
| 3212 | CreateRemoteAnswer(session_->local_description())); |
| 3213 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3214 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3215 | JsepSessionDescription* modified_answer = |
| 3216 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3217 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3218 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 3219 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3220 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3221 | session_->video_rtp_transport_channel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3224 | // kBundlePolicyMaxbundle and then we call SetRemoteDescription first. |
| 3225 | TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) { |
| 3226 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3227 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3228 | |
| 3229 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3230 | options.use_rtp_mux = true; |
| 3231 | |
| 3232 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3233 | SetRemoteDescriptionWithoutError(offer); |
| 3234 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3235 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3236 | session_->video_rtp_transport_channel()); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3239 | TEST_F(WebRtcSessionTest, TestRequireRtcpMux) { |
| 3240 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3241 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3242 | |
| 3243 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3244 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3245 | SetLocalDescriptionWithoutError(offer); |
| 3246 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3247 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3248 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3249 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3250 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3251 | SessionDescriptionInterface* answer = |
| 3252 | CreateRemoteAnswer(session_->local_description()); |
| 3253 | SetRemoteDescriptionWithoutError(answer); |
| 3254 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3255 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3256 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) { |
| 3260 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3261 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3262 | |
| 3263 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3264 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3265 | SetLocalDescriptionWithoutError(offer); |
| 3266 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3267 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL); |
| 3268 | EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3269 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3270 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3271 | SessionDescriptionInterface* answer = |
| 3272 | CreateRemoteAnswer(session_->local_description()); |
| 3273 | SetRemoteDescriptionWithoutError(answer); |
| 3274 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3275 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3276 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3279 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 3280 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 3281 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3282 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3283 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3284 | |
| 3285 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3286 | options.use_rtp_mux = true; |
| 3287 | |
| 3288 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3289 | std::string offer_str; |
| 3290 | offer->ToString(&offer_str); |
| 3291 | // Disable rtcp-mux |
| 3292 | const std::string rtcp_mux = "rtcp-mux"; |
| 3293 | const std::string xrtcp_mux = "xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3294 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3295 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 3296 | &offer_str); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3297 | JsepSessionDescription* local_offer = |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3298 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3299 | EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3300 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3301 | JsepSessionDescription* remote_offer = |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3302 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3303 | EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3304 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3305 | // Trying unmodified SDP. |
| 3306 | SetLocalDescriptionWithoutError(offer); |
| 3307 | } |
| 3308 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3309 | TEST_F(WebRtcSessionTest, SetAudioPlayout) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3310 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3311 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3312 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3313 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3314 | ASSERT_TRUE(channel != NULL); |
| 3315 | ASSERT_EQ(1u, channel->recv_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3316 | uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 3317 | double volume; |
| 3318 | EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); |
| 3319 | EXPECT_EQ(1, volume); |
solenberg | d4cec0d | 2015-10-09 08:55:48 -0700 | [diff] [blame] | 3320 | session_->SetAudioPlayout(receive_ssrc, false); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 3321 | EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); |
| 3322 | EXPECT_EQ(0, volume); |
solenberg | d4cec0d | 2015-10-09 08:55:48 -0700 | [diff] [blame] | 3323 | session_->SetAudioPlayout(receive_ssrc, true); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 3324 | EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); |
| 3325 | EXPECT_EQ(1, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | TEST_F(WebRtcSessionTest, SetAudioSend) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3329 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3330 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3331 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3332 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3333 | ASSERT_TRUE(channel != NULL); |
| 3334 | ASSERT_EQ(1u, channel->send_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3335 | uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3336 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3337 | |
| 3338 | cricket::AudioOptions options; |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 3339 | options.echo_cancellation = rtc::Optional<bool>(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3340 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3341 | rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource()); |
| 3342 | session_->SetAudioSend(send_ssrc, false, options, source.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3343 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 3344 | EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation); |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3345 | EXPECT_TRUE(source->sink() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3346 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3347 | // This will trigger SetSink(nullptr) to the |source|. |
| 3348 | session_->SetAudioSend(send_ssrc, true, options, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3349 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 3350 | EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation); |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3351 | EXPECT_TRUE(source->sink() == nullptr); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3354 | TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3355 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3356 | SendAudioVideoStream1(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3357 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3358 | cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3359 | ASSERT_TRUE(channel != NULL); |
| 3360 | ASSERT_EQ(1u, channel->send_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3361 | uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3362 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3363 | rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource()); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3364 | cricket::AudioOptions options; |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3365 | session_->SetAudioSend(send_ssrc, true, options, source.get()); |
| 3366 | EXPECT_TRUE(source->sink() != nullptr); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3367 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3368 | // Delete the |source| and it will trigger OnClose() to the sink, and this |
| 3369 | // will invalidate the |source_| pointer in the sink and prevent getting a |
| 3370 | // SetSink(nullptr) callback afterwards. |
| 3371 | source.reset(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3372 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 3373 | // This will trigger SetSink(nullptr) if no OnClose() callback. |
| 3374 | session_->SetAudioSend(send_ssrc, true, options, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | TEST_F(WebRtcSessionTest, SetVideoPlayout) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3378 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3379 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3380 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3381 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 3382 | ASSERT_TRUE(channel != NULL); |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 3383 | ASSERT_LT(0u, channel->sinks().size()); |
| 3384 | EXPECT_TRUE(channel->sinks().begin()->second == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3385 | ASSERT_EQ(1u, channel->recv_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3386 | uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3387 | cricket::FakeVideoRenderer renderer; |
| 3388 | session_->SetVideoPlayout(receive_ssrc, true, &renderer); |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 3389 | EXPECT_TRUE(channel->sinks().begin()->second == &renderer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3390 | session_->SetVideoPlayout(receive_ssrc, false, &renderer); |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 3391 | EXPECT_TRUE(channel->sinks().begin()->second == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | TEST_F(WebRtcSessionTest, SetVideoSend) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3395 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3396 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3397 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3398 | cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); |
| 3399 | ASSERT_TRUE(channel != NULL); |
| 3400 | ASSERT_EQ(1u, channel->send_streams().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3401 | uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3402 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3403 | cricket::VideoOptions* options = NULL; |
| 3404 | session_->SetVideoSend(send_ssrc, false, options); |
| 3405 | EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); |
| 3406 | session_->SetVideoSend(send_ssrc, true, options); |
| 3407 | EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); |
| 3408 | } |
| 3409 | |
| 3410 | TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { |
| 3411 | TestCanInsertDtmf(false); |
| 3412 | } |
| 3413 | |
| 3414 | TEST_F(WebRtcSessionTest, CanInsertDtmf) { |
| 3415 | TestCanInsertDtmf(true); |
| 3416 | } |
| 3417 | |
| 3418 | TEST_F(WebRtcSessionTest, InsertDtmf) { |
| 3419 | // Setup |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3420 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3421 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3422 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3423 | FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); |
| 3424 | EXPECT_EQ(0U, channel->dtmf_info_queue().size()); |
| 3425 | |
| 3426 | // Insert DTMF |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3427 | const int expected_duration = 90; |
| 3428 | session_->InsertDtmf(kAudioTrack1, 0, expected_duration); |
| 3429 | session_->InsertDtmf(kAudioTrack1, 1, expected_duration); |
| 3430 | session_->InsertDtmf(kAudioTrack1, 2, expected_duration); |
| 3431 | |
| 3432 | // Verify |
| 3433 | ASSERT_EQ(3U, channel->dtmf_info_queue().size()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3434 | const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3435 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 3436 | expected_duration)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3437 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 3438 | expected_duration)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3439 | EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 3440 | expected_duration)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3443 | // This test verifies the |initial_offerer| flag when session initiates the |
| 3444 | // call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3445 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3446 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3447 | EXPECT_FALSE(session_->initial_offerer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3448 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3449 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3450 | SetLocalDescriptionWithoutError(offer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3451 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3452 | SetRemoteDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3453 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3454 | } |
| 3455 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3456 | // This test verifies the |initial_offerer| flag when session receives the call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3457 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3458 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3459 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3460 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3461 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3462 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3463 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3464 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3465 | SetLocalDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3466 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3467 | } |
| 3468 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3469 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 3470 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3471 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3472 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3473 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3474 | SetLocalDescriptionWithoutError(offer); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3475 | rtc::scoped_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3476 | CreateRemoteAnswer(session_->local_description())); |
| 3477 | |
| 3478 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3479 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3480 | JsepSessionDescription* modified_answer = |
| 3481 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3482 | |
| 3483 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 3484 | answer->session_id(), |
| 3485 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3486 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3487 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3488 | // Different content names. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3489 | std::string sdp; |
| 3490 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 3491 | const std::string kAudioMid = "a=mid:audio"; |
| 3492 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3493 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3494 | kAudioMidReplaceStr.c_str(), |
| 3495 | kAudioMidReplaceStr.length(), |
| 3496 | &sdp); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3497 | SessionDescriptionInterface* modified_answer1 = |
| 3498 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3499 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3500 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3501 | // Different media types. |
| 3502 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 3503 | const std::string kAudioMline = "m=audio"; |
| 3504 | const std::string kAudioMlineReplaceStr = "m=video"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3505 | rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(), |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3506 | kAudioMlineReplaceStr.c_str(), |
| 3507 | kAudioMlineReplaceStr.length(), |
| 3508 | &sdp); |
| 3509 | SessionDescriptionInterface* modified_answer2 = |
| 3510 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 3511 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2); |
| 3512 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3513 | SetRemoteDescriptionWithoutError(answer.release()); |
| 3514 | } |
| 3515 | |
| 3516 | // Verifying remote offer and local answer have matching m-lines as per |
| 3517 | // RFC 3264. |
| 3518 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3519 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3520 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3521 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3522 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3523 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3524 | |
| 3525 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3526 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3527 | JsepSessionDescription* modified_answer = |
| 3528 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3529 | |
| 3530 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 3531 | answer->session_id(), |
| 3532 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3533 | SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3534 | SetLocalDescriptionWithoutError(answer); |
| 3535 | } |
| 3536 | |
| 3537 | // This test verifies that WebRtcSession does not start candidate allocation |
| 3538 | // before SetLocalDescription is called. |
| 3539 | TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3540 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3541 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3542 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3543 | cricket::Candidate candidate; |
| 3544 | candidate.set_component(1); |
| 3545 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 3546 | candidate); |
| 3547 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 3548 | cricket::Candidate candidate1; |
| 3549 | candidate1.set_component(1); |
| 3550 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 3551 | candidate1); |
| 3552 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 3553 | SetRemoteDescriptionWithoutError(offer); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3554 | ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL); |
| 3555 | ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3556 | |
| 3557 | // Pump for 1 second and verify that no candidates are generated. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3558 | rtc::Thread::Current()->ProcessMessages(1000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3559 | EXPECT_TRUE(observer_.mline_0_candidates_.empty()); |
| 3560 | EXPECT_TRUE(observer_.mline_1_candidates_.empty()); |
| 3561 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3562 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3563 | SetLocalDescriptionWithoutError(answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3564 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 3565 | } |
| 3566 | |
| 3567 | // This test verifies that crypto parameter is updated in local session |
| 3568 | // description as per security policy set in MediaSessionDescriptionFactory. |
| 3569 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3570 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3571 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3572 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3573 | |
| 3574 | // Making sure SetLocalDescription correctly sets crypto value in |
| 3575 | // SessionDescription object after de-serialization of sdp string. The value |
| 3576 | // will be set as per MediaSessionDescriptionFactory. |
| 3577 | std::string offer_str; |
| 3578 | offer->ToString(&offer_str); |
| 3579 | SessionDescriptionInterface* jsep_offer_str = |
| 3580 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 3581 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 3582 | EXPECT_TRUE(session_->voice_channel()->secure_required()); |
| 3583 | EXPECT_TRUE(session_->video_channel()->secure_required()); |
| 3584 | } |
| 3585 | |
| 3586 | // This test verifies the crypto parameter when security is disabled. |
| 3587 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3588 | options_.disable_encryption = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3589 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3590 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3591 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3592 | |
| 3593 | // Making sure SetLocalDescription correctly sets crypto value in |
| 3594 | // SessionDescription object after de-serialization of sdp string. The value |
| 3595 | // will be set as per MediaSessionDescriptionFactory. |
| 3596 | std::string offer_str; |
| 3597 | offer->ToString(&offer_str); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3598 | SessionDescriptionInterface* jsep_offer_str = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3599 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 3600 | SetLocalDescriptionWithoutError(jsep_offer_str); |
| 3601 | EXPECT_FALSE(session_->voice_channel()->secure_required()); |
| 3602 | EXPECT_FALSE(session_->video_channel()->secure_required()); |
| 3603 | } |
| 3604 | |
| 3605 | // This test verifies that an answer contains new ufrag and password if an offer |
| 3606 | // with new ufrag and password is received. |
| 3607 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3608 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3609 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3610 | options.recv_video = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3611 | rtc::scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3612 | CreateRemoteOffer(options)); |
| 3613 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3614 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3615 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3616 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3617 | SetLocalDescriptionWithoutError(answer.release()); |
| 3618 | |
| 3619 | // Receive an offer with new ufrag and password. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3620 | for (const cricket::ContentInfo& content : |
| 3621 | session_->local_description()->description()->contents()) { |
| 3622 | options.transport_options[content.name].ice_restart = true; |
| 3623 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3624 | rtc::scoped_ptr<JsepSessionDescription> updated_offer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3625 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3626 | SetRemoteDescriptionWithoutError(updated_offer1.release()); |
| 3627 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3628 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3629 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3630 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(), |
| 3631 | session_->local_description()->description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3632 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3633 | // Even a second answer (created before the description is set) should have |
| 3634 | // a new ufrag/password. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3635 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3636 | |
| 3637 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(), |
| 3638 | session_->local_description()->description())); |
| 3639 | |
| 3640 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 3641 | } |
| 3642 | |
| 3643 | // This test verifies that an answer contains new ufrag and password if an offer |
| 3644 | // that changes either the ufrag or password (but not both) is received. |
| 3645 | // RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or |
| 3646 | // a=ice-pwd attributes compared to the previous SDP from the peer, it |
| 3647 | // indicates that ICE is restarting for this media stream." |
| 3648 | TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) { |
| 3649 | Init(); |
| 3650 | cricket::MediaSessionOptions options; |
| 3651 | options.recv_audio = true; |
| 3652 | options.recv_video = true; |
| 3653 | // Create an offer with audio and video. |
| 3654 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
| 3655 | SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345"); |
| 3656 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3657 | |
| 3658 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3659 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3660 | SetLocalDescriptionWithoutError(answer.release()); |
| 3661 | |
| 3662 | // Receive an offer with a new ufrag but stale password. |
| 3663 | rtc::scoped_ptr<JsepSessionDescription> ufrag_changed_offer( |
| 3664 | CreateRemoteOffer(options, session_->remote_description())); |
| 3665 | SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag", |
| 3666 | "original_password12345"); |
| 3667 | SetRemoteDescriptionWithoutError(ufrag_changed_offer.release()); |
| 3668 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3669 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3670 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(), |
| 3671 | session_->local_description()->description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3672 | SetLocalDescriptionWithoutError(updated_answer1.release()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3673 | |
| 3674 | // Receive an offer with a new password but stale ufrag. |
| 3675 | rtc::scoped_ptr<JsepSessionDescription> password_changed_offer( |
| 3676 | CreateRemoteOffer(options, session_->remote_description())); |
| 3677 | SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag", |
| 3678 | "modified_password12345"); |
| 3679 | SetRemoteDescriptionWithoutError(password_changed_offer.release()); |
| 3680 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3681 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3682 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(), |
| 3683 | session_->local_description()->description())); |
| 3684 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3685 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3686 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3687 | // This test verifies that an answer contains old ufrag and password if an offer |
| 3688 | // with old ufrag and password is received. |
| 3689 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3690 | Init(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3691 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3692 | options.recv_video = true; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3693 | rtc::scoped_ptr<JsepSessionDescription> offer( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3694 | CreateRemoteOffer(options)); |
| 3695 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3696 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3697 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3698 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3699 | SetLocalDescriptionWithoutError(answer.release()); |
| 3700 | |
| 3701 | // Receive an offer without changed ufrag or password. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3702 | rtc::scoped_ptr<JsepSessionDescription> updated_offer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3703 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3704 | SetRemoteDescriptionWithoutError(updated_offer2.release()); |
| 3705 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3706 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3707 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3708 | EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(), |
| 3709 | session_->local_description()->description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3710 | |
| 3711 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 3712 | } |
| 3713 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3714 | // This test verifies that if an offer does an ICE restart on some, but not all |
| 3715 | // media sections, the answer will change the ufrag/password in the correct |
| 3716 | // media sections. |
| 3717 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) { |
| 3718 | Init(); |
| 3719 | cricket::MediaSessionOptions options; |
| 3720 | options.recv_video = true; |
| 3721 | options.recv_audio = true; |
| 3722 | options.bundle_enabled = false; |
| 3723 | rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
| 3724 | |
| 3725 | SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa", |
| 3726 | "aaaaaaaaaaaaaaaaaaaaaa"); |
| 3727 | SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb", |
| 3728 | "bbbbbbbbbbbbbbbbbbbbbb"); |
| 3729 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3730 | |
| 3731 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3732 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3733 | SetLocalDescriptionWithoutError(answer.release()); |
| 3734 | |
| 3735 | // Receive an offer with new ufrag and password, but only for the video media |
| 3736 | // section. |
| 3737 | rtc::scoped_ptr<JsepSessionDescription> updated_offer( |
| 3738 | CreateRemoteOffer(options, session_->remote_description())); |
| 3739 | SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc", |
| 3740 | "cccccccccccccccccccccc"); |
| 3741 | SetRemoteDescriptionWithoutError(updated_offer.release()); |
| 3742 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3743 | rtc::scoped_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3744 | |
| 3745 | EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(), |
| 3746 | session_->local_description()->description(), |
| 3747 | cricket::MEDIA_TYPE_AUDIO)); |
| 3748 | |
| 3749 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(), |
| 3750 | session_->local_description()->description(), |
| 3751 | cricket::MEDIA_TYPE_VIDEO)); |
| 3752 | |
| 3753 | SetLocalDescriptionWithoutError(updated_answer.release()); |
| 3754 | } |
| 3755 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3756 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3757 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3758 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3759 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3760 | const std::string session_id_orig = offer->session_id(); |
| 3761 | const std::string session_version_orig = offer->session_version(); |
| 3762 | SetLocalDescriptionWithoutError(offer); |
| 3763 | |
| 3764 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3765 | video_channel_->set_fail_set_send_codecs(true); |
| 3766 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3767 | SessionDescriptionInterface* answer = |
| 3768 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3769 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3770 | |
| 3771 | // Test that after a content error, setting any description will |
| 3772 | // result in an error. |
| 3773 | video_channel_->set_fail_set_send_codecs(false); |
| 3774 | answer = CreateRemoteAnswer(session_->local_description()); |
| 3775 | SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer); |
| 3776 | offer = CreateRemoteOffer(); |
| 3777 | SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 3781 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 3782 | // Lets try with only UDP ports. |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3783 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3784 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3785 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3786 | TestLoopbackCall(); |
| 3787 | } |
| 3788 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3789 | TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3790 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3791 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3792 | cricket::PORTALLOCATOR_ENABLE_IPV6 | |
| 3793 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 3794 | |
| 3795 | // best connection is IPv6 since it has higher network preference. |
| 3796 | LoopbackNetworkConfiguration config; |
| 3797 | config.test_ipv6_network_ = true; |
| 3798 | config.best_connection_after_initial_ice_converged_ = |
| 3799 | LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1); |
| 3800 | |
| 3801 | TestLoopbackCall(config); |
| 3802 | } |
| 3803 | |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 3804 | // Runs the loopback call test with BUNDLE and STUN enabled. |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3805 | TEST_F(WebRtcSessionTest, TestIceStatesBundle) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3806 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 3807 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3808 | TestLoopbackCall(); |
| 3809 | } |
| 3810 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3811 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3812 | configuration_.enable_rtp_data_channel = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3813 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3814 | SetLocalDescriptionWithDataChannel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3815 | ASSERT_TRUE(data_engine_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3816 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 3817 | } |
| 3818 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3819 | TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3820 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3821 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3822 | configuration_.enable_rtp_data_channel = true; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3823 | options_.disable_sctp_data_channels = false; |
| 3824 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3825 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3826 | |
| 3827 | SetLocalDescriptionWithDataChannel(); |
| 3828 | EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type()); |
| 3829 | } |
| 3830 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3831 | TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3832 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 3833 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3834 | InitWithDtls(GetParam()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3835 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3836 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3837 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3838 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 3839 | } |
| 3840 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3841 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3842 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3843 | SetFactoryDtlsSrtp(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3844 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3845 | |
| 3846 | // Create remote offer with SCTP. |
| 3847 | cricket::MediaSessionOptions options; |
| 3848 | options.data_channel_type = cricket::DCT_SCTP; |
| 3849 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3850 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3851 | SetRemoteDescriptionWithoutError(offer); |
| 3852 | |
| 3853 | // Verifies the answer contains SCTP. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3854 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3855 | EXPECT_TRUE(answer != NULL); |
| 3856 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 3857 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3860 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3861 | configuration_.enable_dtls_srtp = rtc::Optional<bool>(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3862 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3863 | |
| 3864 | SetLocalDescriptionWithDataChannel(); |
| 3865 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 3866 | } |
| 3867 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3868 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3869 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3870 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3871 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3872 | |
| 3873 | SetLocalDescriptionWithDataChannel(); |
| 3874 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 3875 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3876 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3877 | TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3878 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3879 | options_.disable_sctp_data_channels = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3880 | InitWithDtls(GetParam()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3881 | |
| 3882 | SetLocalDescriptionWithDataChannel(); |
| 3883 | EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type()); |
| 3884 | } |
| 3885 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3886 | TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3887 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3888 | const int new_send_port = 9998; |
| 3889 | const int new_recv_port = 7775; |
| 3890 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3891 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3892 | SetFactoryDtlsSrtp(); |
| 3893 | |
| 3894 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 3895 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 3896 | // let the session description get parsed. That'll get the proper codecs |
| 3897 | // into the stream. |
| 3898 | cricket::MediaSessionOptions options; |
| 3899 | JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort( |
| 3900 | "stream1", new_send_port, options); |
| 3901 | |
| 3902 | // SetRemoteDescription will take the ownership of the offer. |
| 3903 | SetRemoteDescriptionWithoutError(offer); |
| 3904 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3905 | SessionDescriptionInterface* answer = |
| 3906 | ChangeSDPSctpPort(new_recv_port, CreateAnswer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3907 | ASSERT_TRUE(answer != NULL); |
| 3908 | |
| 3909 | // Now set the local description, which'll take ownership of the answer. |
| 3910 | SetLocalDescriptionWithoutError(answer); |
| 3911 | |
| 3912 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 3913 | // and pass it all the way down. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3914 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3915 | CreateDataChannel(); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3916 | |
| 3917 | cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0); |
| 3918 | int portnum = -1; |
| 3919 | ASSERT_TRUE(ch != NULL); |
| 3920 | ASSERT_EQ(1UL, ch->send_codecs().size()); |
| 3921 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3922 | EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3923 | ch->send_codecs()[0].name.c_str())); |
| 3924 | EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 3925 | &portnum)); |
| 3926 | EXPECT_EQ(new_send_port, portnum); |
| 3927 | |
| 3928 | ASSERT_EQ(1UL, ch->recv_codecs().size()); |
| 3929 | EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3930 | EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3931 | ch->recv_codecs()[0].name.c_str())); |
| 3932 | EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort, |
| 3933 | &portnum)); |
| 3934 | EXPECT_EQ(new_recv_port, portnum); |
| 3935 | } |
| 3936 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3937 | // Verifies that when a session's DataChannel receives an OPEN message, |
| 3938 | // WebRtcSession signals the DataChannel creation request with the expected |
| 3939 | // config. |
| 3940 | TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) { |
| 3941 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 3942 | |
| 3943 | InitWithDtls(GetParam()); |
| 3944 | |
| 3945 | SetLocalDescriptionWithDataChannel(); |
| 3946 | EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type()); |
| 3947 | |
| 3948 | webrtc::DataChannelInit config; |
| 3949 | config.id = 1; |
| 3950 | rtc::Buffer payload; |
| 3951 | webrtc::WriteDataChannelOpenMessage("a", config, &payload); |
| 3952 | cricket::ReceiveDataParams params; |
| 3953 | params.ssrc = config.id; |
| 3954 | params.type = cricket::DMT_CONTROL; |
| 3955 | |
| 3956 | cricket::DataChannel* data_channel = session_->data_channel(); |
| 3957 | data_channel->SignalDataReceived(data_channel, params, payload); |
| 3958 | |
| 3959 | EXPECT_EQ("a", last_data_channel_label_); |
| 3960 | EXPECT_EQ(config.id, last_data_channel_config_.id); |
| 3961 | EXPECT_FALSE(last_data_channel_config_.negotiated); |
| 3962 | EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker, |
| 3963 | last_data_channel_config_.open_handshake_role); |
| 3964 | } |
| 3965 | |
| 3966 | TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) { |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3967 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
| 3968 | FakeDtlsIdentityStore::GenerateCertificate(); |
| 3969 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3970 | configuration_.certificates.push_back(certificate); |
| 3971 | Init(); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3972 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
| 3973 | |
| 3974 | EXPECT_EQ(session_->certificate_for_testing(), certificate); |
| 3975 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3976 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3977 | // Verifies that CreateOffer succeeds when CreateOffer is called before async |
| 3978 | // identity generation is finished (even if a certificate is provided this is |
| 3979 | // an async op). |
| 3980 | TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { |
| 3981 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
| 3982 | InitWithDtls(GetParam()); |
| 3983 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 3984 | EXPECT_TRUE(session_->waiting_for_certificate_for_testing()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3985 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3986 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 3987 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3988 | EXPECT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3989 | VerifyNoCryptoParams(offer->description(), true); |
| 3990 | VerifyFingerprintStatus(offer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | // Verifies that CreateAnswer succeeds when CreateOffer is called before async |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3994 | // identity generation is finished (even if a certificate is provided this is |
| 3995 | // an async op). |
| 3996 | TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3997 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3998 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3999 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4000 | |
| 4001 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 4002 | options.recv_video = true; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4003 | scoped_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4004 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4005 | ASSERT_TRUE(offer.get() != NULL); |
| 4006 | SetRemoteDescriptionWithoutError(offer.release()); |
| 4007 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4008 | rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4009 | EXPECT_TRUE(answer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4010 | VerifyNoCryptoParams(answer->description(), true); |
| 4011 | VerifyFingerprintStatus(answer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | // Verifies that CreateOffer succeeds when CreateOffer is called after async |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4015 | // identity generation is finished (even if a certificate is provided this is |
| 4016 | // an async op). |
| 4017 | TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4018 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4019 | InitWithDtls(GetParam()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4020 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4021 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4022 | |
| 4023 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4024 | EXPECT_TRUE(offer != NULL); |
| 4025 | } |
| 4026 | |
| 4027 | // Verifies that CreateOffer fails when CreateOffer is called after async |
| 4028 | // identity generation fails. |
| 4029 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4030 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4031 | InitWithDtlsIdentityGenFail(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4032 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4033 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4034 | |
| 4035 | rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4036 | EXPECT_TRUE(offer == NULL); |
| 4037 | } |
| 4038 | |
| 4039 | // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made |
| 4040 | // before async identity generation is finished. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4041 | TEST_P(WebRtcSessionTest, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4042 | TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4043 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4044 | VerifyMultipleAsyncCreateDescription(GetParam(), |
| 4045 | CreateSessionDescriptionRequest::kOffer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | // Verifies that CreateOffer fails when Multiple CreateOffer calls are made |
| 4049 | // before async identity generation fails. |
| 4050 | TEST_F(WebRtcSessionTest, |
| 4051 | TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4052 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4053 | VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 4054 | CreateSessionDescriptionRequest::kOffer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | // Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made |
| 4058 | // before async identity generation is finished. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4059 | TEST_P(WebRtcSessionTest, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4060 | TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4061 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4062 | VerifyMultipleAsyncCreateDescription( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4063 | GetParam(), CreateSessionDescriptionRequest::kAnswer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | // Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made |
| 4067 | // before async identity generation fails. |
| 4068 | TEST_F(WebRtcSessionTest, |
| 4069 | TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4070 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4071 | VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 4072 | CreateSessionDescriptionRequest::kAnswer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4073 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 4074 | |
| 4075 | // Verifies that setRemoteDescription fails when DTLS is disabled and the remote |
| 4076 | // offer has no SDES crypto but only DTLS fingerprint. |
| 4077 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { |
| 4078 | // Init without DTLS. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 4079 | Init(); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 4080 | // Create a remote offer with secured transport disabled. |
| 4081 | cricket::MediaSessionOptions options; |
| 4082 | JsepSessionDescription* offer(CreateRemoteOffer( |
| 4083 | options, cricket::SEC_DISABLED)); |
| 4084 | // Adds a DTLS fingerprint to the remote offer. |
| 4085 | cricket::SessionDescription* sdp = offer->description(); |
| 4086 | TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 4087 | ASSERT_TRUE(audio != NULL); |
| 4088 | ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); |
| 4089 | audio->description.identity_fingerprint.reset( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4090 | rtc::SSLFingerprint::CreateFromRfc4572( |
| 4091 | rtc::DIGEST_SHA_256, kFakeDtlsFingerprint)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4092 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 4093 | offer); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 4096 | TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4097 | configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 4098 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4099 | SendAudioVideoStream1(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 4100 | SessionDescriptionInterface* offer = CreateOffer(); |
| 4101 | |
| 4102 | SetLocalDescriptionWithoutError(offer); |
| 4103 | |
| 4104 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 4105 | |
| 4106 | ASSERT_TRUE(voice_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 4107 | const cricket::AudioOptions& audio_options = voice_channel_->options(); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 4108 | EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4111 | // Tests that we can renegotiate new media content with ICE candidates in the |
| 4112 | // new remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4113 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4114 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4115 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4116 | SetFactoryDtlsSrtp(); |
| 4117 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4118 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4119 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4120 | SetLocalDescriptionWithoutError(offer); |
| 4121 | |
| 4122 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 4123 | SetRemoteDescriptionWithoutError(answer); |
| 4124 | |
| 4125 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 4126 | options.recv_video = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4127 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 4128 | |
| 4129 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4130 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4131 | candidate1.set_component(1); |
| 4132 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 4133 | candidate1); |
| 4134 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 4135 | SetRemoteDescriptionWithoutError(offer); |
| 4136 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4137 | answer = CreateAnswer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4138 | SetLocalDescriptionWithoutError(answer); |
| 4139 | } |
| 4140 | |
| 4141 | // Tests that we can renegotiate new media content with ICE candidates separated |
| 4142 | // from the remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4143 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4144 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4145 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4146 | SetFactoryDtlsSrtp(); |
| 4147 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4148 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4149 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4150 | SetLocalDescriptionWithoutError(offer); |
| 4151 | |
| 4152 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 4153 | SetRemoteDescriptionWithoutError(answer); |
| 4154 | |
| 4155 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 4156 | options.recv_video = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4157 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 4158 | SetRemoteDescriptionWithoutError(offer); |
| 4159 | |
| 4160 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4161 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4162 | candidate1.set_component(1); |
| 4163 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 4164 | candidate1); |
| 4165 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate)); |
| 4166 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4167 | answer = CreateAnswer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4168 | SetLocalDescriptionWithoutError(answer); |
| 4169 | } |
honghaiz | 7f77749 | 2016-02-02 21:54:01 -0800 | [diff] [blame] | 4170 | |
| 4171 | // Flaky on Win and Mac only. See webrtc:4943 |
| 4172 | #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) |
| 4173 | #define MAYBE_TestRtxRemovedByCreateAnswer DISABLED_TestRtxRemovedByCreateAnswer |
| 4174 | #else |
| 4175 | #define MAYBE_TestRtxRemovedByCreateAnswer TestRtxRemovedByCreateAnswer |
| 4176 | #endif |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4177 | // Tests that RTX codec is removed from the answer when it isn't supported |
| 4178 | // by local side. |
honghaiz | 7f77749 | 2016-02-02 21:54:01 -0800 | [diff] [blame] | 4179 | TEST_F(WebRtcSessionTest, MAYBE_TestRtxRemovedByCreateAnswer) { |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4180 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4181 | SendAudioVideoStream1(); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4182 | std::string offer_sdp(kSdpWithRtx); |
| 4183 | |
| 4184 | SessionDescriptionInterface* offer = |
| 4185 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL); |
| 4186 | EXPECT_TRUE(offer->ToString(&offer_sdp)); |
| 4187 | |
| 4188 | // Offer SDP contains the RTX codec. |
| 4189 | EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos); |
| 4190 | SetRemoteDescriptionWithoutError(offer); |
| 4191 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4192 | SessionDescriptionInterface* answer = CreateAnswer(); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4193 | std::string answer_sdp; |
| 4194 | answer->ToString(&answer_sdp); |
| 4195 | // Answer SDP removes the unsupported RTX codec. |
| 4196 | EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos); |
| 4197 | SetLocalDescriptionWithoutError(answer); |
| 4198 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4199 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4200 | // This verifies that the voice channel after bundle has both options from video |
| 4201 | // and voice channels. |
| 4202 | TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { |
| 4203 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4204 | SendAudioVideoStream1(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4205 | |
| 4206 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4207 | options.use_rtp_mux = true; |
| 4208 | |
| 4209 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 4210 | SetLocalDescriptionWithoutError(offer); |
| 4211 | |
| 4212 | session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 4213 | rtc::Socket::Option::OPT_SNDBUF, 4000); |
| 4214 | |
| 4215 | session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 4216 | rtc::Socket::Option::OPT_RCVBUF, 8000); |
| 4217 | |
| 4218 | int option_val; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4219 | EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4220 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 4221 | EXPECT_EQ(4000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4222 | EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4223 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 4224 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4225 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4226 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 4227 | EXPECT_EQ(8000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4228 | EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4229 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 4230 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4231 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 4232 | session_->video_rtp_transport_channel()); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4233 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4234 | SendAudioVideoStream2(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4235 | SessionDescriptionInterface* answer = |
| 4236 | CreateRemoteAnswer(session_->local_description()); |
| 4237 | SetRemoteDescriptionWithoutError(answer); |
| 4238 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4239 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4240 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 4241 | EXPECT_EQ(4000, option_val); |
| 4242 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4243 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4244 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 4245 | EXPECT_EQ(8000, option_val); |
| 4246 | } |
| 4247 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4248 | // Test creating a session, request multiple offers, destroy the session |
| 4249 | // and make sure we got success/failure callbacks for all of the requests. |
| 4250 | // Background: crbug.com/507307 |
| 4251 | TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { |
| 4252 | Init(); |
| 4253 | |
| 4254 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100]; |
| 4255 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4256 | options.offer_to_receive_audio = |
| 4257 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4258 | cricket::MediaSessionOptions session_options; |
| 4259 | session_options.recv_audio = true; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4260 | |
| 4261 | for (auto& o : observers) { |
| 4262 | o = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4263 | session_->CreateOffer(o, options, session_options); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | session_.reset(); |
| 4267 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4268 | for (auto& o : observers) { |
| 4269 | // We expect to have received a notification now even if the session was |
| 4270 | // terminated. The offer creation may or may not have succeeded, but we |
| 4271 | // must have received a notification which, so the only invalid state |
| 4272 | // is kInit. |
| 4273 | EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); |
| 4274 | } |
| 4275 | } |
| 4276 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 4277 | TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
| 4278 | TestPacketOptions(); |
| 4279 | } |
| 4280 | |
deadbeef | 057ecf0 | 2016-01-20 14:30:43 -0800 | [diff] [blame] | 4281 | // Make sure the signal from "GetOnDestroyedSignal()" fires when the session |
| 4282 | // is destroyed. |
| 4283 | TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) { |
| 4284 | Init(); |
| 4285 | session_.reset(); |
| 4286 | EXPECT_TRUE(session_destroyed_); |
| 4287 | } |
| 4288 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4289 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 4290 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 4291 | // called more than once without returning to IceGatheringGathering. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4292 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4293 | INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 4294 | WebRtcSessionTest, |
| 4295 | testing::Values(ALREADY_GENERATED, |
| 4296 | DTLS_IDENTITY_STORE)); |