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