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