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