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