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