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