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