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