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