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