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