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