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