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