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