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