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