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