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