Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 13 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 14 | #include <memory> |
| 15 | #include <string> |
| 16 | #include <tuple> |
| 17 | #include <type_traits> |
| 18 | #include <utility> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "absl/types/optional.h" |
| 22 | #include "api/audio/audio_mixer.h" |
| 23 | #include "api/candidate.h" |
| 24 | #include "api/ice_transport_interface.h" |
| 25 | #include "api/jsep.h" |
| 26 | #include "api/media_types.h" |
| 27 | #include "api/peer_connection_interface.h" |
| 28 | #include "api/rtc_error.h" |
| 29 | #include "api/scoped_refptr.h" |
| 30 | #include "modules/audio_device/include/audio_device.h" |
| 31 | #include "modules/audio_processing/include/audio_processing.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "p2p/base/fake_port_allocator.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 33 | #include "p2p/base/ice_transport_internal.h" |
| 34 | #include "p2p/base/p2p_constants.h" |
| 35 | #include "p2p/base/port.h" |
| 36 | #include "p2p/base/port_allocator.h" |
| 37 | #include "p2p/base/transport_description.h" |
| 38 | #include "p2p/base/transport_info.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 39 | #include "p2p/client/basic_port_allocator.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 40 | #include "pc/channel_interface.h" |
| 41 | #include "pc/dtls_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 42 | #include "pc/media_session.h" |
| 43 | #include "pc/peer_connection.h" |
| 44 | #include "pc/peer_connection_wrapper.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 45 | #include "pc/rtp_transceiver.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 46 | #include "pc/sdp_utils.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 47 | #include "pc/session_description.h" |
| 48 | #include "rtc_base/checks.h" |
Byoungchan Lee | d197e0b | 2022-05-30 23:59:55 +0900 | [diff] [blame] | 49 | #include "rtc_base/internal/default_socket_server.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 50 | #include "rtc_base/ip_address.h" |
| 51 | #include "rtc_base/logging.h" |
| 52 | #include "rtc_base/net_helper.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 53 | #include "rtc_base/rtc_certificate_generator.h" |
| 54 | #include "rtc_base/socket_address.h" |
| 55 | #include "rtc_base/thread.h" |
| 56 | #include "test/gtest.h" |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 57 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 58 | #include "pc/test/android_test_initializer.h" |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 59 | #endif |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 60 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 61 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 62 | #include "api/create_peerconnection_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 63 | #include "api/uma_metrics.h" |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 64 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 65 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
Markus Handell | a1b8201 | 2021-05-26 18:56:30 +0200 | [diff] [blame] | 66 | #include "pc/peer_connection_proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 67 | #include "pc/test/fake_audio_capture_module.h" |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 68 | #include "pc/test/mock_peer_connection_observers.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 69 | #include "rtc_base/fake_network.h" |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 70 | #include "rtc_base/gunit.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 71 | #include "rtc_base/strings/string_builder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 72 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 73 | #include "system_wrappers/include/metrics.h" |
Steve Anton | b443dfe | 2019-03-05 14:09:49 -0800 | [diff] [blame] | 74 | #include "test/gmock.h" |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 75 | |
| 76 | namespace webrtc { |
| 77 | |
| 78 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 79 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
| 80 | using rtc::SocketAddress; |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 81 | using ::testing::Combine; |
Steve Anton | b443dfe | 2019-03-05 14:09:49 -0800 | [diff] [blame] | 82 | using ::testing::ElementsAre; |
| 83 | using ::testing::Pair; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 84 | using ::testing::Values; |
| 85 | |
| 86 | constexpr int kIceCandidatesTimeout = 10000; |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 87 | constexpr int64_t kWaitTimeout = 10000; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 88 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 89 | class PeerConnectionWrapperForIceTest : public PeerConnectionWrapper { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 90 | public: |
| 91 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 92 | |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 93 | std::unique_ptr<IceCandidateInterface> CreateJsepCandidateForFirstTransport( |
| 94 | cricket::Candidate* candidate) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 95 | RTC_DCHECK(pc()->remote_description()); |
| 96 | const auto* desc = pc()->remote_description()->description(); |
| 97 | RTC_DCHECK(desc->contents().size() > 0); |
| 98 | const auto& first_content = desc->contents()[0]; |
| 99 | candidate->set_transport_name(first_content.name); |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 100 | return CreateIceCandidate(first_content.name, -1, *candidate); |
| 101 | } |
| 102 | |
| 103 | // Adds a new ICE candidate to the first transport. |
| 104 | bool AddIceCandidate(cricket::Candidate* candidate) { |
| 105 | return pc()->AddIceCandidate( |
| 106 | CreateJsepCandidateForFirstTransport(candidate).get()); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // Returns ICE candidates from the remote session description. |
| 110 | std::vector<const IceCandidateInterface*> |
| 111 | GetIceCandidatesFromRemoteDescription() { |
| 112 | const SessionDescriptionInterface* sdesc = pc()->remote_description(); |
| 113 | RTC_DCHECK(sdesc); |
| 114 | std::vector<const IceCandidateInterface*> candidates; |
| 115 | for (size_t mline_index = 0; mline_index < sdesc->number_of_mediasections(); |
| 116 | mline_index++) { |
| 117 | const auto* candidate_collection = sdesc->candidates(mline_index); |
| 118 | for (size_t i = 0; i < candidate_collection->count(); i++) { |
| 119 | candidates.push_back(candidate_collection->at(i)); |
| 120 | } |
| 121 | } |
| 122 | return candidates; |
| 123 | } |
| 124 | |
| 125 | rtc::FakeNetworkManager* network() { return network_; } |
| 126 | |
| 127 | void set_network(rtc::FakeNetworkManager* network) { network_ = network; } |
| 128 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 129 | // The port allocator used by this PC. |
| 130 | cricket::PortAllocator* port_allocator_; |
| 131 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 132 | private: |
| 133 | rtc::FakeNetworkManager* network_; |
| 134 | }; |
| 135 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 136 | class PeerConnectionIceBaseTest : public ::testing::Test { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 137 | protected: |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 138 | typedef std::unique_ptr<PeerConnectionWrapperForIceTest> WrapperPtr; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 139 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 140 | explicit PeerConnectionIceBaseTest(SdpSemantics sdp_semantics) |
| 141 | : vss_(new rtc::VirtualSocketServer()), |
| 142 | main_(vss_.get()), |
| 143 | sdp_semantics_(sdp_semantics) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 144 | #ifdef WEBRTC_ANDROID |
| 145 | InitializeAndroidObjects(); |
| 146 | #endif |
| 147 | pc_factory_ = CreatePeerConnectionFactory( |
| 148 | rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 149 | rtc::scoped_refptr<AudioDeviceModule>(FakeAudioCaptureModule::Create()), |
| 150 | CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), |
| 151 | CreateBuiltinVideoEncoderFactory(), CreateBuiltinVideoDecoderFactory(), |
| 152 | nullptr /* audio_mixer */, nullptr /* audio_processing */); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | WrapperPtr CreatePeerConnection() { |
| 156 | return CreatePeerConnection(RTCConfiguration()); |
| 157 | } |
| 158 | |
| 159 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
| 160 | auto* fake_network = NewFakeNetwork(); |
Byoungchan Lee | d197e0b | 2022-05-30 23:59:55 +0900 | [diff] [blame] | 161 | auto port_allocator = std::make_unique<cricket::BasicPortAllocator>( |
| 162 | fake_network, |
| 163 | std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 164 | port_allocator->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 165 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 166 | port_allocator->set_step_delay(cricket::kMinimumStepDelay); |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 167 | RTCConfiguration modified_config = config; |
| 168 | modified_config.sdp_semantics = sdp_semantics_; |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 169 | auto observer = std::make_unique<MockPeerConnectionObserver>(); |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 170 | auto port_allocator_copy = port_allocator.get(); |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 171 | PeerConnectionDependencies pc_dependencies(observer.get()); |
| 172 | pc_dependencies.allocator = std::move(port_allocator); |
| 173 | auto result = pc_factory_->CreatePeerConnectionOrError( |
| 174 | modified_config, std::move(pc_dependencies)); |
| 175 | if (!result.ok()) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 176 | return nullptr; |
| 177 | } |
| 178 | |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 179 | observer->SetPeerConnectionInterface(result.value().get()); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 180 | auto wrapper = std::make_unique<PeerConnectionWrapperForIceTest>( |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 181 | pc_factory_, result.MoveValue(), std::move(observer)); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 182 | wrapper->set_network(fake_network); |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 183 | wrapper->port_allocator_ = port_allocator_copy; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 184 | return wrapper; |
| 185 | } |
| 186 | |
| 187 | // Accepts the same arguments as CreatePeerConnection and adds default audio |
| 188 | // and video tracks. |
| 189 | template <typename... Args> |
| 190 | WrapperPtr CreatePeerConnectionWithAudioVideo(Args&&... args) { |
| 191 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 192 | if (!wrapper) { |
| 193 | return nullptr; |
| 194 | } |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 195 | wrapper->AddAudioTrack("a"); |
| 196 | wrapper->AddVideoTrack("v"); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 197 | return wrapper; |
| 198 | } |
| 199 | |
| 200 | cricket::Candidate CreateLocalUdpCandidate( |
| 201 | const rtc::SocketAddress& address) { |
| 202 | cricket::Candidate candidate; |
| 203 | candidate.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 204 | candidate.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| 205 | candidate.set_address(address); |
| 206 | candidate.set_type(cricket::LOCAL_PORT_TYPE); |
| 207 | return candidate; |
| 208 | } |
| 209 | |
| 210 | // Remove all ICE ufrag/pwd lines from the given session description. |
| 211 | void RemoveIceUfragPwd(SessionDescriptionInterface* sdesc) { |
| 212 | SetIceUfragPwd(sdesc, "", ""); |
| 213 | } |
| 214 | |
| 215 | // Sets all ICE ufrag/pwds on the given session description. |
| 216 | void SetIceUfragPwd(SessionDescriptionInterface* sdesc, |
| 217 | const std::string& ufrag, |
| 218 | const std::string& pwd) { |
| 219 | auto* desc = sdesc->description(); |
| 220 | for (const auto& content : desc->contents()) { |
| 221 | auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 222 | transport_info->description.ice_ufrag = ufrag; |
| 223 | transport_info->description.ice_pwd = pwd; |
| 224 | } |
| 225 | } |
| 226 | |
Qingsi Wang | e169272 | 2017-11-29 13:27:20 -0800 | [diff] [blame] | 227 | // Set ICE mode on the given session description. |
| 228 | void SetIceMode(SessionDescriptionInterface* sdesc, |
| 229 | const cricket::IceMode ice_mode) { |
| 230 | auto* desc = sdesc->description(); |
| 231 | for (const auto& content : desc->contents()) { |
| 232 | auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 233 | transport_info->description.ice_mode = ice_mode; |
| 234 | } |
| 235 | } |
| 236 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 237 | cricket::TransportDescription* GetFirstTransportDescription( |
| 238 | SessionDescriptionInterface* sdesc) { |
| 239 | auto* desc = sdesc->description(); |
| 240 | RTC_DCHECK(desc->contents().size() > 0); |
| 241 | auto* transport_info = |
| 242 | desc->GetTransportInfoByName(desc->contents()[0].name); |
| 243 | RTC_DCHECK(transport_info); |
| 244 | return &transport_info->description; |
| 245 | } |
| 246 | |
| 247 | const cricket::TransportDescription* GetFirstTransportDescription( |
| 248 | const SessionDescriptionInterface* sdesc) { |
| 249 | auto* desc = sdesc->description(); |
| 250 | RTC_DCHECK(desc->contents().size() > 0); |
| 251 | auto* transport_info = |
| 252 | desc->GetTransportInfoByName(desc->contents()[0].name); |
| 253 | RTC_DCHECK(transport_info); |
| 254 | return &transport_info->description; |
| 255 | } |
| 256 | |
Qingsi Wang | e169272 | 2017-11-29 13:27:20 -0800 | [diff] [blame] | 257 | // TODO(qingsi): Rewrite this method in terms of the standard IceTransport |
| 258 | // after it is implemented. |
| 259 | cricket::IceRole GetIceRole(const WrapperPtr& pc_wrapper_ptr) { |
Mirko Bonadei | e97de91 | 2017-12-13 11:29:34 +0100 | [diff] [blame] | 260 | auto* pc_proxy = |
| 261 | static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>( |
| 262 | pc_wrapper_ptr->pc()); |
| 263 | PeerConnection* pc = static_cast<PeerConnection*>(pc_proxy->internal()); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 264 | for (const auto& transceiver : pc->GetTransceiversInternal()) { |
Steve Anton | 6947025 | 2018-02-09 11:43:08 -0800 | [diff] [blame] | 265 | if (transceiver->media_type() == cricket::MEDIA_TYPE_AUDIO) { |
Bjorn A Mellem | 3a1b927 | 2019-05-24 16:13:08 -0700 | [diff] [blame] | 266 | auto dtls_transport = pc->LookupDtlsTransportByMidInternal( |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 267 | transceiver->internal()->channel()->mid()); |
Bjorn A Mellem | 3a1b927 | 2019-05-24 16:13:08 -0700 | [diff] [blame] | 268 | return dtls_transport->ice_transport()->internal()->GetIceRole(); |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
Artem Titov | d325196 | 2021-11-15 16:57:07 +0100 | [diff] [blame] | 271 | RTC_DCHECK_NOTREACHED(); |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 272 | return cricket::ICEROLE_UNKNOWN; |
Qingsi Wang | e169272 | 2017-11-29 13:27:20 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 275 | // Returns a list of (ufrag, pwd) pairs in the order that they appear in |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 276 | // `description`, or the empty list if `description` is null. |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 277 | std::vector<std::pair<std::string, std::string>> GetIceCredentials( |
| 278 | const SessionDescriptionInterface* description) { |
| 279 | std::vector<std::pair<std::string, std::string>> ice_credentials; |
| 280 | if (!description) |
| 281 | return ice_credentials; |
| 282 | const auto* desc = description->description(); |
| 283 | for (const auto& content_info : desc->contents()) { |
| 284 | const auto* transport_info = |
| 285 | desc->GetTransportInfoByName(content_info.name); |
| 286 | if (transport_info) { |
| 287 | ice_credentials.push_back( |
| 288 | std::make_pair(transport_info->description.ice_ufrag, |
| 289 | transport_info->description.ice_pwd)); |
| 290 | } |
| 291 | } |
| 292 | return ice_credentials; |
| 293 | } |
| 294 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 295 | bool AddCandidateToFirstTransport(cricket::Candidate* candidate, |
| 296 | SessionDescriptionInterface* sdesc) { |
| 297 | auto* desc = sdesc->description(); |
| 298 | RTC_DCHECK(desc->contents().size() > 0); |
| 299 | const auto& first_content = desc->contents()[0]; |
| 300 | candidate->set_transport_name(first_content.name); |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 301 | std::unique_ptr<IceCandidateInterface> jsep_candidate = |
| 302 | CreateIceCandidate(first_content.name, 0, *candidate); |
| 303 | return sdesc->AddCandidate(jsep_candidate.get()); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | rtc::FakeNetworkManager* NewFakeNetwork() { |
| 307 | // The PeerConnection's port allocator is tied to the PeerConnection's |
| 308 | // lifetime and expects the underlying NetworkManager to outlive it. That |
| 309 | // prevents us from having the PeerConnectionWrapper own the fake network. |
| 310 | // Therefore, the test fixture will own all the fake networks even though |
| 311 | // tests should access the fake network through the PeerConnectionWrapper. |
| 312 | auto* fake_network = new rtc::FakeNetworkManager(); |
| 313 | fake_networks_.emplace_back(fake_network); |
| 314 | return fake_network; |
| 315 | } |
| 316 | |
| 317 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 318 | rtc::AutoSocketServerThread main_; |
| 319 | rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_; |
| 320 | std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_networks_; |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 321 | const SdpSemantics sdp_semantics_; |
| 322 | }; |
| 323 | |
| 324 | class PeerConnectionIceTest |
| 325 | : public PeerConnectionIceBaseTest, |
| 326 | public ::testing::WithParamInterface<SdpSemantics> { |
| 327 | protected: |
Harald Alvestrand | 76829d7 | 2018-07-18 23:24:36 +0200 | [diff] [blame] | 328 | PeerConnectionIceTest() : PeerConnectionIceBaseTest(GetParam()) { |
| 329 | webrtc::metrics::Reset(); |
| 330 | } |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | ::testing::AssertionResult AssertCandidatesEqual(const char* a_expr, |
| 334 | const char* b_expr, |
| 335 | const cricket::Candidate& a, |
| 336 | const cricket::Candidate& b) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 337 | rtc::StringBuilder failure_info; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 338 | if (a.component() != b.component()) { |
| 339 | failure_info << "\ncomponent: " << a.component() << " != " << b.component(); |
| 340 | } |
| 341 | if (a.protocol() != b.protocol()) { |
| 342 | failure_info << "\nprotocol: " << a.protocol() << " != " << b.protocol(); |
| 343 | } |
| 344 | if (a.address() != b.address()) { |
| 345 | failure_info << "\naddress: " << a.address().ToString() |
| 346 | << " != " << b.address().ToString(); |
| 347 | } |
| 348 | if (a.type() != b.type()) { |
| 349 | failure_info << "\ntype: " << a.type() << " != " << b.type(); |
| 350 | } |
| 351 | std::string failure_info_str = failure_info.str(); |
| 352 | if (failure_info_str.empty()) { |
| 353 | return ::testing::AssertionSuccess(); |
| 354 | } else { |
| 355 | return ::testing::AssertionFailure() |
| 356 | << a_expr << " and " << b_expr << " are not equal" |
| 357 | << failure_info_str; |
| 358 | } |
| 359 | } |
| 360 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 361 | TEST_P(PeerConnectionIceTest, OfferContainsGatheredCandidates) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 362 | const SocketAddress kLocalAddress("1.1.1.1", 0); |
| 363 | |
| 364 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 365 | caller->network()->AddInterface(kLocalAddress); |
| 366 | |
| 367 | // Start ICE candidate gathering by setting the local offer. |
| 368 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 369 | |
| 370 | EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kIceCandidatesTimeout); |
| 371 | |
| 372 | auto offer = caller->CreateOffer(); |
| 373 | EXPECT_LT(0u, caller->observer()->GetCandidatesByMline(0).size()); |
| 374 | EXPECT_EQ(caller->observer()->GetCandidatesByMline(0).size(), |
| 375 | offer->candidates(0)->count()); |
| 376 | EXPECT_LT(0u, caller->observer()->GetCandidatesByMline(1).size()); |
| 377 | EXPECT_EQ(caller->observer()->GetCandidatesByMline(1).size(), |
| 378 | offer->candidates(1)->count()); |
| 379 | } |
| 380 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 381 | TEST_P(PeerConnectionIceTest, AnswerContainsGatheredCandidates) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 382 | const SocketAddress kCallerAddress("1.1.1.1", 0); |
| 383 | |
| 384 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 385 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 386 | caller->network()->AddInterface(kCallerAddress); |
| 387 | |
| 388 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 389 | ASSERT_TRUE(callee->SetLocalDescription(callee->CreateAnswer())); |
| 390 | |
| 391 | EXPECT_TRUE_WAIT(callee->IsIceGatheringDone(), kIceCandidatesTimeout); |
| 392 | |
Steve Anton | dffead8 | 2018-02-06 10:31:29 -0800 | [diff] [blame] | 393 | auto* answer = callee->pc()->local_description(); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 394 | EXPECT_LT(0u, caller->observer()->GetCandidatesByMline(0).size()); |
| 395 | EXPECT_EQ(callee->observer()->GetCandidatesByMline(0).size(), |
| 396 | answer->candidates(0)->count()); |
| 397 | EXPECT_LT(0u, caller->observer()->GetCandidatesByMline(1).size()); |
| 398 | EXPECT_EQ(callee->observer()->GetCandidatesByMline(1).size(), |
| 399 | answer->candidates(1)->count()); |
| 400 | } |
| 401 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 402 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 403 | CanSetRemoteSessionDescriptionWithRemoteCandidates) { |
| 404 | const SocketAddress kCallerAddress("1.1.1.1", 1111); |
| 405 | |
| 406 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 407 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 408 | |
| 409 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 410 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCallerAddress); |
| 411 | AddCandidateToFirstTransport(&candidate, offer.get()); |
| 412 | |
| 413 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 414 | auto remote_candidates = callee->GetIceCandidatesFromRemoteDescription(); |
| 415 | ASSERT_EQ(1u, remote_candidates.size()); |
| 416 | EXPECT_PRED_FORMAT2(AssertCandidatesEqual, candidate, |
| 417 | remote_candidates[0]->candidate()); |
| 418 | } |
| 419 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 420 | TEST_P(PeerConnectionIceTest, SetLocalDescriptionFailsIfNoIceCredentials) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 421 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 422 | |
| 423 | auto offer = caller->CreateOffer(); |
| 424 | RemoveIceUfragPwd(offer.get()); |
| 425 | |
| 426 | EXPECT_FALSE(caller->SetLocalDescription(std::move(offer))); |
| 427 | } |
| 428 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 429 | TEST_P(PeerConnectionIceTest, SetRemoteDescriptionFailsIfNoIceCredentials) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 430 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 431 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 432 | |
| 433 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 434 | RemoveIceUfragPwd(offer.get()); |
| 435 | |
| 436 | EXPECT_FALSE(callee->SetRemoteDescription(std::move(offer))); |
| 437 | } |
| 438 | |
Steve Anton | f764cf4 | 2018-05-01 14:32:17 -0700 | [diff] [blame] | 439 | // Test that doing an offer/answer exchange with no transport (i.e., no data |
| 440 | // channel or media) results in the ICE connection state staying at New. |
| 441 | TEST_P(PeerConnectionIceTest, |
| 442 | OfferAnswerWithNoTransportsDoesNotChangeIceConnectionState) { |
| 443 | auto caller = CreatePeerConnection(); |
| 444 | auto callee = CreatePeerConnection(); |
| 445 | |
| 446 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 447 | |
| 448 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 449 | caller->pc()->ice_connection_state()); |
| 450 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 451 | callee->pc()->ice_connection_state()); |
| 452 | } |
| 453 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 454 | // The following group tests that ICE candidates are not generated before |
| 455 | // SetLocalDescription is called on a PeerConnection. |
| 456 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 457 | TEST_P(PeerConnectionIceTest, NoIceCandidatesBeforeSetLocalDescription) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 458 | const SocketAddress kLocalAddress("1.1.1.1", 0); |
| 459 | |
| 460 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 461 | caller->network()->AddInterface(kLocalAddress); |
| 462 | |
| 463 | // Pump for 1 second and verify that no candidates are generated. |
| 464 | rtc::Thread::Current()->ProcessMessages(1000); |
| 465 | |
| 466 | EXPECT_EQ(0u, caller->observer()->candidates_.size()); |
| 467 | } |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 468 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 469 | NoIceCandidatesBeforeAnswerSetAsLocalDescription) { |
| 470 | const SocketAddress kCallerAddress("1.1.1.1", 1111); |
| 471 | |
| 472 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 473 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 474 | caller->network()->AddInterface(kCallerAddress); |
| 475 | |
| 476 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 477 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCallerAddress); |
| 478 | AddCandidateToFirstTransport(&candidate, offer.get()); |
| 479 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 480 | |
| 481 | // Pump for 1 second and verify that no candidates are generated. |
| 482 | rtc::Thread::Current()->ProcessMessages(1000); |
| 483 | |
| 484 | EXPECT_EQ(0u, callee->observer()->candidates_.size()); |
| 485 | } |
| 486 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 487 | TEST_P(PeerConnectionIceTest, CannotAddCandidateWhenRemoteDescriptionNotSet) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 488 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 489 | |
| 490 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 491 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 492 | std::unique_ptr<IceCandidateInterface> jsep_candidate = |
| 493 | CreateIceCandidate(cricket::CN_AUDIO, 0, candidate); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 494 | |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 495 | EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get())); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 496 | |
| 497 | caller->CreateOfferAndSetAsLocal(); |
| 498 | |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 499 | EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get())); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 500 | EXPECT_METRIC_THAT( |
| 501 | webrtc::metrics::Samples("WebRTC.PeerConnection.AddIceCandidate"), |
| 502 | ElementsAre(Pair(kAddIceCandidateFailNoRemoteDescription, 2))); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 505 | TEST_P(PeerConnectionIceTest, CannotAddCandidateWhenPeerConnectionClosed) { |
| 506 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 507 | |
| 508 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 509 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 510 | |
| 511 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 512 | |
| 513 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
| 514 | auto* audio_content = cricket::GetFirstAudioContent( |
| 515 | caller->pc()->local_description()->description()); |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 516 | std::unique_ptr<IceCandidateInterface> jsep_candidate = |
| 517 | CreateIceCandidate(audio_content->name, 0, candidate); |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 518 | |
| 519 | caller->pc()->Close(); |
| 520 | |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 521 | EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get())); |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 524 | TEST_P(PeerConnectionIceTest, DuplicateIceCandidateIgnoredWhenAdded) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 525 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 526 | |
| 527 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 528 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 529 | |
| 530 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 531 | ASSERT_TRUE( |
| 532 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 533 | |
| 534 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
| 535 | caller->AddIceCandidate(&candidate); |
| 536 | EXPECT_TRUE(caller->AddIceCandidate(&candidate)); |
| 537 | EXPECT_EQ(1u, caller->GetIceCandidatesFromRemoteDescription().size()); |
| 538 | } |
| 539 | |
Tomas Gunnarsson | 27bc6e2 | 2021-02-12 13:16:26 +0100 | [diff] [blame] | 540 | // TODO(tommi): Re-enable after updating RTCPeerConnection-blockedPorts.html in |
| 541 | // Chromium (the test needs setRemoteDescription to succeed for an invalid |
| 542 | // candidate). |
| 543 | TEST_P(PeerConnectionIceTest, DISABLED_ErrorOnInvalidRemoteIceCandidateAdded) { |
Tomas Gunnarsson | 8cb9706 | 2021-02-08 18:57:04 +0100 | [diff] [blame] | 544 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 545 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 546 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 547 | // Add a candidate to the remote description with a candidate that has an |
| 548 | // invalid address (port number == 2). |
| 549 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 550 | cricket::Candidate bad_candidate = |
| 551 | CreateLocalUdpCandidate(SocketAddress("2.2.2.2", 2)); |
| 552 | RTC_LOG(LS_INFO) << "Bad candidate: " << bad_candidate.ToString(); |
| 553 | AddCandidateToFirstTransport(&bad_candidate, answer.get()); |
| 554 | // Now the call to SetRemoteDescription should fail. |
| 555 | EXPECT_FALSE(caller->SetRemoteDescription(std::move(answer))); |
| 556 | } |
| 557 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 558 | TEST_P(PeerConnectionIceTest, |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 559 | CannotRemoveIceCandidatesWhenPeerConnectionClosed) { |
| 560 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 561 | |
| 562 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 563 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 564 | |
| 565 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 566 | |
| 567 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
| 568 | auto* audio_content = cricket::GetFirstAudioContent( |
| 569 | caller->pc()->local_description()->description()); |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 570 | std::unique_ptr<IceCandidateInterface> ice_candidate = |
| 571 | CreateIceCandidate(audio_content->name, 0, candidate); |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 572 | |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 573 | ASSERT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get())); |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 574 | |
| 575 | caller->pc()->Close(); |
| 576 | |
| 577 | EXPECT_FALSE(caller->pc()->RemoveIceCandidates({candidate})); |
| 578 | } |
| 579 | |
| 580 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 581 | AddRemoveCandidateWithEmptyTransportDoesNotCrash) { |
| 582 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 583 | |
| 584 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 585 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 586 | |
| 587 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 588 | ASSERT_TRUE( |
| 589 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 590 | |
Artem Titov | cfea218 | 2021-08-10 01:22:31 +0200 | [diff] [blame] | 591 | // `candidate.transport_name()` is empty. |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 592 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 593 | auto* audio_content = cricket::GetFirstAudioContent( |
| 594 | caller->pc()->local_description()->description()); |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 595 | std::unique_ptr<IceCandidateInterface> ice_candidate = |
| 596 | CreateIceCandidate(audio_content->name, 0, candidate); |
| 597 | EXPECT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get())); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 598 | EXPECT_TRUE(caller->pc()->RemoveIceCandidates({candidate})); |
| 599 | } |
| 600 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 601 | TEST_P(PeerConnectionIceTest, RemoveCandidateRemovesFromRemoteDescription) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 602 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 603 | |
| 604 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 605 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 606 | |
| 607 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 608 | ASSERT_TRUE( |
| 609 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 610 | |
| 611 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
| 612 | ASSERT_TRUE(caller->AddIceCandidate(&candidate)); |
| 613 | EXPECT_TRUE(caller->pc()->RemoveIceCandidates({candidate})); |
| 614 | EXPECT_EQ(0u, caller->GetIceCandidatesFromRemoteDescription().size()); |
| 615 | } |
| 616 | |
| 617 | // Test that if a candidate is added via AddIceCandidate and via an updated |
| 618 | // remote description, then both candidates appear in the stored remote |
| 619 | // description. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 620 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 621 | CandidateInSubsequentOfferIsAddedToRemoteDescription) { |
| 622 | const SocketAddress kCallerAddress1("1.1.1.1", 1111); |
| 623 | const SocketAddress kCallerAddress2("2.2.2.2", 2222); |
| 624 | |
| 625 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 626 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 627 | |
| 628 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 629 | ASSERT_TRUE( |
| 630 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 631 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 632 | // Add one candidate via `AddIceCandidate`. |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 633 | cricket::Candidate candidate1 = CreateLocalUdpCandidate(kCallerAddress1); |
| 634 | ASSERT_TRUE(callee->AddIceCandidate(&candidate1)); |
| 635 | |
| 636 | // Add the second candidate via a reoffer. |
| 637 | auto offer = caller->CreateOffer(); |
| 638 | cricket::Candidate candidate2 = CreateLocalUdpCandidate(kCallerAddress2); |
| 639 | AddCandidateToFirstTransport(&candidate2, offer.get()); |
| 640 | |
| 641 | // Expect both candidates to appear in the callee's remote description. |
| 642 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 643 | EXPECT_EQ(2u, callee->GetIceCandidatesFromRemoteDescription().size()); |
| 644 | } |
| 645 | |
| 646 | // The follow test verifies that SetLocal/RemoteDescription fails when an offer |
| 647 | // has either ICE ufrag/pwd too short or too long and succeeds otherwise. |
| 648 | // The standard (https://tools.ietf.org/html/rfc5245#section-15.4) says that |
| 649 | // pwd must be 22-256 characters and ufrag must be 4-256 characters. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 650 | TEST_P(PeerConnectionIceTest, VerifyUfragPwdLength) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 651 | auto set_local_description_with_ufrag_pwd_length = [this](int ufrag_len, |
| 652 | int pwd_len) { |
| 653 | auto pc = CreatePeerConnectionWithAudioVideo(); |
| 654 | auto offer = pc->CreateOffer(); |
| 655 | SetIceUfragPwd(offer.get(), std::string(ufrag_len, 'x'), |
| 656 | std::string(pwd_len, 'x')); |
| 657 | return pc->SetLocalDescription(std::move(offer)); |
| 658 | }; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 659 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 660 | auto set_remote_description_with_ufrag_pwd_length = [this](int ufrag_len, |
| 661 | int pwd_len) { |
| 662 | auto pc = CreatePeerConnectionWithAudioVideo(); |
| 663 | auto offer = pc->CreateOffer(); |
| 664 | SetIceUfragPwd(offer.get(), std::string(ufrag_len, 'x'), |
| 665 | std::string(pwd_len, 'x')); |
| 666 | return pc->SetRemoteDescription(std::move(offer)); |
| 667 | }; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 668 | |
| 669 | EXPECT_FALSE(set_local_description_with_ufrag_pwd_length(3, 22)); |
| 670 | EXPECT_FALSE(set_remote_description_with_ufrag_pwd_length(3, 22)); |
| 671 | EXPECT_FALSE(set_local_description_with_ufrag_pwd_length(257, 22)); |
| 672 | EXPECT_FALSE(set_remote_description_with_ufrag_pwd_length(257, 22)); |
| 673 | EXPECT_FALSE(set_local_description_with_ufrag_pwd_length(4, 21)); |
| 674 | EXPECT_FALSE(set_remote_description_with_ufrag_pwd_length(4, 21)); |
| 675 | EXPECT_FALSE(set_local_description_with_ufrag_pwd_length(4, 257)); |
| 676 | EXPECT_FALSE(set_remote_description_with_ufrag_pwd_length(4, 257)); |
| 677 | EXPECT_TRUE(set_local_description_with_ufrag_pwd_length(4, 22)); |
| 678 | EXPECT_TRUE(set_remote_description_with_ufrag_pwd_length(4, 22)); |
| 679 | EXPECT_TRUE(set_local_description_with_ufrag_pwd_length(256, 256)); |
| 680 | EXPECT_TRUE(set_remote_description_with_ufrag_pwd_length(256, 256)); |
| 681 | } |
| 682 | |
| 683 | ::testing::AssertionResult AssertIpInCandidates( |
| 684 | const char* address_expr, |
| 685 | const char* candidates_expr, |
| 686 | const SocketAddress& address, |
| 687 | const std::vector<IceCandidateInterface*> candidates) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 688 | rtc::StringBuilder candidate_hosts; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 689 | for (const auto* candidate : candidates) { |
| 690 | const auto& candidate_ip = candidate->candidate().address().ipaddr(); |
| 691 | if (candidate_ip == address.ipaddr()) { |
| 692 | return ::testing::AssertionSuccess(); |
| 693 | } |
Jonas Olsson | abbe841 | 2018-04-03 13:40:05 +0200 | [diff] [blame] | 694 | candidate_hosts << "\n" << candidate_ip.ToString(); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 695 | } |
| 696 | return ::testing::AssertionFailure() |
| 697 | << address_expr << " (host " << address.HostAsURIString() |
| 698 | << ") not in " << candidates_expr |
| 699 | << " which have the following address hosts:" << candidate_hosts.str(); |
| 700 | } |
| 701 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 702 | TEST_P(PeerConnectionIceTest, CandidatesGeneratedForEachLocalInterface) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 703 | const SocketAddress kLocalAddress1("1.1.1.1", 0); |
| 704 | const SocketAddress kLocalAddress2("2.2.2.2", 0); |
| 705 | |
| 706 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 707 | caller->network()->AddInterface(kLocalAddress1); |
| 708 | caller->network()->AddInterface(kLocalAddress2); |
| 709 | |
| 710 | caller->CreateOfferAndSetAsLocal(); |
| 711 | EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kIceCandidatesTimeout); |
| 712 | |
| 713 | auto candidates = caller->observer()->GetCandidatesByMline(0); |
| 714 | EXPECT_PRED_FORMAT2(AssertIpInCandidates, kLocalAddress1, candidates); |
| 715 | EXPECT_PRED_FORMAT2(AssertIpInCandidates, kLocalAddress2, candidates); |
| 716 | } |
| 717 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 718 | TEST_P(PeerConnectionIceTest, TrickledSingleCandidateAddedToRemoteDescription) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 719 | const SocketAddress kCallerAddress("1.1.1.1", 1111); |
| 720 | |
| 721 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 722 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 723 | |
| 724 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 725 | |
| 726 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCallerAddress); |
| 727 | callee->AddIceCandidate(&candidate); |
| 728 | auto candidates = callee->GetIceCandidatesFromRemoteDescription(); |
| 729 | ASSERT_EQ(1u, candidates.size()); |
| 730 | EXPECT_PRED_FORMAT2(AssertCandidatesEqual, candidate, |
| 731 | candidates[0]->candidate()); |
| 732 | } |
| 733 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 734 | TEST_P(PeerConnectionIceTest, TwoTrickledCandidatesAddedToRemoteDescription) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 735 | const SocketAddress kCalleeAddress1("1.1.1.1", 1111); |
| 736 | const SocketAddress kCalleeAddress2("2.2.2.2", 2222); |
| 737 | |
| 738 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 739 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 740 | |
| 741 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 742 | ASSERT_TRUE( |
| 743 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 744 | |
| 745 | cricket::Candidate candidate1 = CreateLocalUdpCandidate(kCalleeAddress1); |
| 746 | caller->AddIceCandidate(&candidate1); |
| 747 | |
| 748 | cricket::Candidate candidate2 = CreateLocalUdpCandidate(kCalleeAddress2); |
| 749 | caller->AddIceCandidate(&candidate2); |
| 750 | |
| 751 | auto candidates = caller->GetIceCandidatesFromRemoteDescription(); |
| 752 | ASSERT_EQ(2u, candidates.size()); |
| 753 | EXPECT_PRED_FORMAT2(AssertCandidatesEqual, candidate1, |
| 754 | candidates[0]->candidate()); |
| 755 | EXPECT_PRED_FORMAT2(AssertCandidatesEqual, candidate2, |
| 756 | candidates[1]->candidate()); |
| 757 | } |
| 758 | |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 759 | TEST_P(PeerConnectionIceTest, AsyncAddIceCandidateIsAddedToRemoteDescription) { |
| 760 | auto candidate = CreateLocalUdpCandidate(SocketAddress("1.1.1.1", 1111)); |
| 761 | |
| 762 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 763 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 764 | |
| 765 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 766 | |
| 767 | auto jsep_candidate = |
| 768 | callee->CreateJsepCandidateForFirstTransport(&candidate); |
| 769 | bool operation_completed = false; |
| 770 | callee->pc()->AddIceCandidate(std::move(jsep_candidate), |
| 771 | [&operation_completed](RTCError result) { |
| 772 | EXPECT_TRUE(result.ok()); |
| 773 | operation_completed = true; |
| 774 | }); |
| 775 | EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout); |
| 776 | |
| 777 | auto candidates = callee->GetIceCandidatesFromRemoteDescription(); |
| 778 | ASSERT_EQ(1u, candidates.size()); |
| 779 | EXPECT_PRED_FORMAT2(AssertCandidatesEqual, candidate, |
| 780 | candidates[0]->candidate()); |
| 781 | } |
| 782 | |
| 783 | TEST_P(PeerConnectionIceTest, |
| 784 | AsyncAddIceCandidateCompletesImmediatelyIfNoPendingOperation) { |
| 785 | auto candidate = CreateLocalUdpCandidate(SocketAddress("1.1.1.1", 1111)); |
| 786 | |
| 787 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 788 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 789 | |
| 790 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 791 | |
| 792 | auto jsep_candidate = |
| 793 | callee->CreateJsepCandidateForFirstTransport(&candidate); |
| 794 | bool operation_completed = false; |
| 795 | callee->pc()->AddIceCandidate( |
| 796 | std::move(jsep_candidate), |
| 797 | [&operation_completed](RTCError result) { operation_completed = true; }); |
| 798 | EXPECT_TRUE(operation_completed); |
| 799 | } |
| 800 | |
| 801 | TEST_P(PeerConnectionIceTest, |
| 802 | AsyncAddIceCandidateCompletesWhenPendingOperationCompletes) { |
| 803 | auto candidate = CreateLocalUdpCandidate(SocketAddress("1.1.1.1", 1111)); |
| 804 | |
| 805 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 806 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 807 | |
| 808 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 809 | |
| 810 | // Chain an operation that will block AddIceCandidate() from executing. |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 811 | auto answer_observer = |
| 812 | rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 813 | callee->pc()->CreateAnswer(answer_observer.get(), RTCOfferAnswerOptions()); |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 814 | |
| 815 | auto jsep_candidate = |
| 816 | callee->CreateJsepCandidateForFirstTransport(&candidate); |
| 817 | bool operation_completed = false; |
| 818 | callee->pc()->AddIceCandidate( |
| 819 | std::move(jsep_candidate), |
| 820 | [&operation_completed](RTCError result) { operation_completed = true; }); |
| 821 | // The operation will not be able to complete until we EXPECT_TRUE_WAIT() |
| 822 | // allowing CreateAnswer() to complete. |
| 823 | EXPECT_FALSE(operation_completed); |
| 824 | EXPECT_TRUE_WAIT(answer_observer->called(), kWaitTimeout); |
| 825 | // As soon as it does, AddIceCandidate() will execute without delay, so it |
| 826 | // must also have completed. |
| 827 | EXPECT_TRUE(operation_completed); |
| 828 | } |
| 829 | |
| 830 | TEST_P(PeerConnectionIceTest, |
| 831 | AsyncAddIceCandidateFailsBeforeSetRemoteDescription) { |
| 832 | auto candidate = CreateLocalUdpCandidate(SocketAddress("1.1.1.1", 1111)); |
| 833 | |
| 834 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 835 | std::unique_ptr<IceCandidateInterface> jsep_candidate = |
| 836 | CreateIceCandidate(cricket::CN_AUDIO, 0, candidate); |
| 837 | |
| 838 | bool operation_completed = false; |
| 839 | caller->pc()->AddIceCandidate( |
| 840 | std::move(jsep_candidate), [&operation_completed](RTCError result) { |
| 841 | EXPECT_FALSE(result.ok()); |
| 842 | EXPECT_EQ(result.message(), |
Henrik Boström | 347488e | 2022-01-21 15:18:08 +0100 | [diff] [blame] | 843 | std::string("The remote description was null")); |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 844 | operation_completed = true; |
| 845 | }); |
| 846 | EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout); |
| 847 | } |
| 848 | |
| 849 | TEST_P(PeerConnectionIceTest, |
| 850 | AsyncAddIceCandidateFailsIfPeerConnectionDestroyed) { |
| 851 | auto candidate = CreateLocalUdpCandidate(SocketAddress("1.1.1.1", 1111)); |
| 852 | |
| 853 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 854 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 855 | |
| 856 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 857 | |
| 858 | // Chain an operation that will block AddIceCandidate() from executing. |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 859 | auto answer_observer = |
| 860 | rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 861 | callee->pc()->CreateAnswer(answer_observer.get(), RTCOfferAnswerOptions()); |
Henrik Boström | ee6f4f6 | 2019-11-06 12:36:12 +0100 | [diff] [blame] | 862 | |
| 863 | auto jsep_candidate = |
| 864 | callee->CreateJsepCandidateForFirstTransport(&candidate); |
| 865 | bool operation_completed = false; |
| 866 | callee->pc()->AddIceCandidate( |
| 867 | std::move(jsep_candidate), [&operation_completed](RTCError result) { |
| 868 | EXPECT_FALSE(result.ok()); |
| 869 | EXPECT_EQ( |
| 870 | result.message(), |
| 871 | std::string( |
| 872 | "AddIceCandidate failed because the session was shut down")); |
| 873 | operation_completed = true; |
| 874 | }); |
| 875 | // The operation will not be able to run until EXPECT_TRUE_WAIT(), giving us |
| 876 | // time to remove all references to the PeerConnection. |
| 877 | EXPECT_FALSE(operation_completed); |
| 878 | // This should delete the callee PC. |
| 879 | callee = nullptr; |
| 880 | EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout); |
| 881 | } |
| 882 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 883 | TEST_P(PeerConnectionIceTest, LocalDescriptionUpdatedWhenContinualGathering) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 884 | const SocketAddress kLocalAddress("1.1.1.1", 0); |
| 885 | |
| 886 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 887 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 888 | config.continual_gathering_policy = |
| 889 | PeerConnectionInterface::GATHER_CONTINUALLY; |
| 890 | auto caller = CreatePeerConnectionWithAudioVideo(config); |
| 891 | caller->network()->AddInterface(kLocalAddress); |
| 892 | |
| 893 | // Start ICE candidate gathering by setting the local offer. |
| 894 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 895 | |
| 896 | // Since we're using continual gathering, we won't get "gathering done". |
| 897 | EXPECT_TRUE_WAIT( |
| 898 | caller->pc()->local_description()->candidates(0)->count() > 0, |
| 899 | kIceCandidatesTimeout); |
| 900 | } |
| 901 | |
| 902 | // Test that when continual gathering is enabled, and a network interface goes |
| 903 | // down, the candidate is signaled as removed and removed from the local |
| 904 | // description. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 905 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 906 | LocalCandidatesRemovedWhenNetworkDownIfGatheringContinually) { |
| 907 | const SocketAddress kLocalAddress("1.1.1.1", 0); |
| 908 | |
| 909 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 910 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 911 | config.continual_gathering_policy = |
| 912 | PeerConnectionInterface::GATHER_CONTINUALLY; |
| 913 | auto caller = CreatePeerConnectionWithAudioVideo(config); |
| 914 | caller->network()->AddInterface(kLocalAddress); |
| 915 | |
| 916 | // Start ICE candidate gathering by setting the local offer. |
| 917 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 918 | |
| 919 | EXPECT_TRUE_WAIT( |
| 920 | caller->pc()->local_description()->candidates(0)->count() > 0, |
| 921 | kIceCandidatesTimeout); |
| 922 | |
| 923 | // Remove the only network interface, causing the PeerConnection to signal |
| 924 | // the removal of all candidates derived from this interface. |
| 925 | caller->network()->RemoveInterface(kLocalAddress); |
| 926 | |
| 927 | EXPECT_EQ_WAIT(0u, caller->pc()->local_description()->candidates(0)->count(), |
| 928 | kIceCandidatesTimeout); |
| 929 | EXPECT_LT(0, caller->observer()->num_candidates_removed_); |
| 930 | } |
| 931 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 932 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 933 | LocalCandidatesNotRemovedWhenNetworkDownIfGatheringOnce) { |
| 934 | const SocketAddress kLocalAddress("1.1.1.1", 0); |
| 935 | |
| 936 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 937 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 938 | config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE; |
| 939 | auto caller = CreatePeerConnectionWithAudioVideo(config); |
| 940 | caller->network()->AddInterface(kLocalAddress); |
| 941 | |
| 942 | // Start ICE candidate gathering by setting the local offer. |
| 943 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 944 | |
| 945 | EXPECT_TRUE_WAIT(caller->IsIceGatheringDone(), kIceCandidatesTimeout); |
| 946 | |
| 947 | caller->network()->RemoveInterface(kLocalAddress); |
| 948 | |
| 949 | // Verify that the local candidates are not removed; |
| 950 | rtc::Thread::Current()->ProcessMessages(1000); |
| 951 | EXPECT_EQ(0, caller->observer()->num_candidates_removed_); |
| 952 | } |
| 953 | |
| 954 | // The following group tests that when an offer includes a new ufrag or pwd |
| 955 | // (indicating an ICE restart) the old candidates are removed and new candidates |
| 956 | // added to the remote description. |
| 957 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 958 | TEST_P(PeerConnectionIceTest, IceRestartOfferClearsExistingCandidate) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 959 | const SocketAddress kCallerAddress("1.1.1.1", 1111); |
| 960 | |
| 961 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 962 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 963 | |
Amit Hilbuch | ae3df54 | 2019-01-07 12:13:08 -0800 | [diff] [blame] | 964 | auto offer = caller->CreateOfferAndSetAsLocal(); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 965 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCallerAddress); |
| 966 | AddCandidateToFirstTransport(&candidate, offer.get()); |
| 967 | |
| 968 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 969 | |
| 970 | RTCOfferAnswerOptions options; |
| 971 | options.ice_restart = true; |
Amit Hilbuch | ae3df54 | 2019-01-07 12:13:08 -0800 | [diff] [blame] | 972 | ASSERT_TRUE( |
| 973 | callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal(options))); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 974 | |
| 975 | EXPECT_EQ(0u, callee->GetIceCandidatesFromRemoteDescription().size()); |
| 976 | } |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 977 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 978 | IceRestartOfferCandidateReplacesExistingCandidate) { |
| 979 | const SocketAddress kFirstCallerAddress("1.1.1.1", 1111); |
| 980 | const SocketAddress kRestartedCallerAddress("2.2.2.2", 2222); |
| 981 | |
| 982 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 983 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 984 | |
Amit Hilbuch | ae3df54 | 2019-01-07 12:13:08 -0800 | [diff] [blame] | 985 | auto offer = caller->CreateOfferAndSetAsLocal(); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 986 | cricket::Candidate old_candidate = |
| 987 | CreateLocalUdpCandidate(kFirstCallerAddress); |
| 988 | AddCandidateToFirstTransport(&old_candidate, offer.get()); |
| 989 | |
| 990 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 991 | |
| 992 | RTCOfferAnswerOptions options; |
| 993 | options.ice_restart = true; |
Amit Hilbuch | ae3df54 | 2019-01-07 12:13:08 -0800 | [diff] [blame] | 994 | auto restart_offer = caller->CreateOfferAndSetAsLocal(options); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 995 | cricket::Candidate new_candidate = |
| 996 | CreateLocalUdpCandidate(kRestartedCallerAddress); |
| 997 | AddCandidateToFirstTransport(&new_candidate, restart_offer.get()); |
| 998 | |
| 999 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(restart_offer))); |
| 1000 | |
| 1001 | auto remote_candidates = callee->GetIceCandidatesFromRemoteDescription(); |
| 1002 | ASSERT_EQ(1u, remote_candidates.size()); |
| 1003 | EXPECT_PRED_FORMAT2(AssertCandidatesEqual, new_candidate, |
| 1004 | remote_candidates[0]->candidate()); |
| 1005 | } |
| 1006 | |
| 1007 | // Test that if there is not an ICE restart (i.e., nothing changes), then the |
| 1008 | // answer to a later offer should have the same ufrag/pwd as the first answer. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1009 | TEST_P(PeerConnectionIceTest, LaterAnswerHasSameIceCredentialsIfNoIceRestart) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1010 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1011 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1012 | |
| 1013 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1014 | ASSERT_TRUE( |
| 1015 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1016 | |
| 1017 | // Re-offer. |
| 1018 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1019 | |
| 1020 | auto answer = callee->CreateAnswer(); |
| 1021 | auto* answer_transport_desc = GetFirstTransportDescription(answer.get()); |
| 1022 | auto* local_transport_desc = |
| 1023 | GetFirstTransportDescription(callee->pc()->local_description()); |
| 1024 | |
| 1025 | EXPECT_EQ(answer_transport_desc->ice_ufrag, local_transport_desc->ice_ufrag); |
| 1026 | EXPECT_EQ(answer_transport_desc->ice_pwd, local_transport_desc->ice_pwd); |
| 1027 | } |
| 1028 | |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1029 | TEST_P(PeerConnectionIceTest, RestartIceGeneratesNewCredentials) { |
| 1030 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1031 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1032 | |
| 1033 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1034 | auto initial_ice_credentials = |
| 1035 | GetIceCredentials(caller->pc()->local_description()); |
| 1036 | caller->pc()->RestartIce(); |
| 1037 | ASSERT_TRUE(caller->CreateOfferAndSetAsLocal()); |
| 1038 | auto restarted_ice_credentials = |
| 1039 | GetIceCredentials(caller->pc()->local_description()); |
| 1040 | EXPECT_NE(initial_ice_credentials, restarted_ice_credentials); |
| 1041 | } |
| 1042 | |
| 1043 | TEST_P(PeerConnectionIceTest, |
| 1044 | RestartIceWhileLocalOfferIsPendingGeneratesNewCredentialsInNextOffer) { |
| 1045 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1046 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1047 | |
| 1048 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1049 | auto initial_ice_credentials = |
| 1050 | GetIceCredentials(caller->pc()->local_description()); |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1051 | // ICE restart becomes needed while an O/A is pending and `caller` is the |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1052 | // offerer. |
| 1053 | caller->pc()->RestartIce(); |
| 1054 | ASSERT_TRUE( |
| 1055 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1056 | ASSERT_TRUE(caller->CreateOfferAndSetAsLocal()); |
| 1057 | auto restarted_ice_credentials = |
| 1058 | GetIceCredentials(caller->pc()->local_description()); |
| 1059 | EXPECT_NE(initial_ice_credentials, restarted_ice_credentials); |
| 1060 | } |
| 1061 | |
| 1062 | TEST_P(PeerConnectionIceTest, |
| 1063 | RestartIceWhileRemoteOfferIsPendingGeneratesNewCredentialsInNextOffer) { |
| 1064 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1065 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1066 | |
| 1067 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1068 | auto initial_ice_credentials = |
| 1069 | GetIceCredentials(caller->pc()->local_description()); |
| 1070 | ASSERT_TRUE(caller->SetRemoteDescription(callee->CreateOfferAndSetAsLocal())); |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1071 | // ICE restart becomes needed while an O/A is pending and `caller` is the |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1072 | // answerer. |
| 1073 | caller->pc()->RestartIce(); |
| 1074 | ASSERT_TRUE( |
| 1075 | callee->SetRemoteDescription(caller->CreateAnswerAndSetAsLocal())); |
| 1076 | ASSERT_TRUE(caller->CreateOfferAndSetAsLocal()); |
| 1077 | auto restarted_ice_credentials = |
| 1078 | GetIceCredentials(caller->pc()->local_description()); |
| 1079 | EXPECT_NE(initial_ice_credentials, restarted_ice_credentials); |
| 1080 | } |
| 1081 | |
| 1082 | TEST_P(PeerConnectionIceTest, RestartIceTriggeredByRemoteSide) { |
| 1083 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1084 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1085 | |
| 1086 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1087 | auto initial_ice_credentials = |
| 1088 | GetIceCredentials(caller->pc()->local_description()); |
| 1089 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1090 | // Remote restart and O/A exchange with `caller` as the answerer should |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1091 | // restart ICE locally as well. |
| 1092 | callee->pc()->RestartIce(); |
| 1093 | ASSERT_TRUE(callee->ExchangeOfferAnswerWith(caller.get())); |
| 1094 | |
| 1095 | auto restarted_ice_credentials = |
| 1096 | GetIceCredentials(caller->pc()->local_description()); |
| 1097 | EXPECT_NE(initial_ice_credentials, restarted_ice_credentials); |
| 1098 | } |
| 1099 | |
| 1100 | TEST_P(PeerConnectionIceTest, RestartIceCausesNegotiationNeeded) { |
| 1101 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1102 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1103 | |
| 1104 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1105 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1106 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1107 | caller->pc()->RestartIce(); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1108 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1109 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | // In Unified Plan, "onnegotiationneeded" is spec-compliant, including not |
| 1113 | // firing multipe times in a row, or firing when returning to the stable |
| 1114 | // signaling state if negotiation is still needed. In Plan B it fires any time |
| 1115 | // something changes. As such, some tests are SdpSemantics-specific. |
| 1116 | class PeerConnectionIceTestUnifiedPlan : public PeerConnectionIceBaseTest { |
| 1117 | protected: |
| 1118 | PeerConnectionIceTestUnifiedPlan() |
| 1119 | : PeerConnectionIceBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 1120 | }; |
| 1121 | |
| 1122 | TEST_F(PeerConnectionIceTestUnifiedPlan, |
| 1123 | RestartIceWhileLocalOfferIsPendingCausesNegotiationNeededWhenStable) { |
| 1124 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1125 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1126 | |
| 1127 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1128 | // ICE restart becomes needed while an O/A is pending and `caller` is the |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1129 | // offerer. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1130 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1131 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1132 | caller->pc()->RestartIce(); |
| 1133 | // In Unified Plan, the event should not fire until we are back in the stable |
| 1134 | // signaling state. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1135 | EXPECT_FALSE(caller->observer()->legacy_renegotiation_needed()); |
| 1136 | EXPECT_FALSE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1137 | ASSERT_TRUE( |
| 1138 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1139 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1140 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | TEST_F(PeerConnectionIceTestUnifiedPlan, |
| 1144 | RestartIceWhileRemoteOfferIsPendingCausesNegotiationNeededWhenStable) { |
| 1145 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1146 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1147 | |
| 1148 | // Establish initial credentials as the caller. |
| 1149 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1150 | ASSERT_TRUE(caller->SetRemoteDescription(callee->CreateOfferAndSetAsLocal())); |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1151 | // ICE restart becomes needed while an O/A is pending and `caller` is the |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1152 | // answerer. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1153 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1154 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1155 | caller->pc()->RestartIce(); |
| 1156 | // In Unified Plan, the event should not fire until we are back in the stable |
| 1157 | // signaling state. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1158 | EXPECT_FALSE(caller->observer()->legacy_renegotiation_needed()); |
| 1159 | EXPECT_FALSE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1160 | ASSERT_TRUE( |
| 1161 | callee->SetRemoteDescription(caller->CreateAnswerAndSetAsLocal())); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1162 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1163 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | TEST_F(PeerConnectionIceTestUnifiedPlan, |
| 1167 | RestartIceTriggeredByRemoteSideCauseNegotiationNotNeeded) { |
| 1168 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1169 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1170 | |
| 1171 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1172 | // Local restart. |
| 1173 | caller->pc()->RestartIce(); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1174 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1175 | caller->observer()->clear_latest_negotiation_needed_event(); |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1176 | // Remote restart and O/A exchange with `caller` as the answerer should |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1177 | // restart ICE locally as well. |
| 1178 | callee->pc()->RestartIce(); |
| 1179 | ASSERT_TRUE(callee->ExchangeOfferAnswerWith(caller.get())); |
| 1180 | // Having restarted ICE by the remote offer, we do not need to renegotiate ICE |
| 1181 | // credentials when back in the stable signaling state. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1182 | EXPECT_FALSE(caller->observer()->legacy_renegotiation_needed()); |
| 1183 | EXPECT_FALSE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | TEST_F(PeerConnectionIceTestUnifiedPlan, |
| 1187 | RestartIceTwiceDoesNotFireNegotiationNeededTwice) { |
| 1188 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1189 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1190 | |
| 1191 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1192 | caller->pc()->RestartIce(); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1193 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1194 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
| 1195 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1196 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1197 | caller->pc()->RestartIce(); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1198 | EXPECT_FALSE(caller->observer()->legacy_renegotiation_needed()); |
| 1199 | EXPECT_FALSE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | // In Plan B, "onnegotiationneeded" is not spec-compliant, firing based on if |
| 1203 | // something changed rather than if negotiation is needed. In Unified Plan it |
| 1204 | // fires according to spec. As such, some tests are SdpSemantics-specific. |
| 1205 | class PeerConnectionIceTestPlanB : public PeerConnectionIceBaseTest { |
| 1206 | protected: |
| 1207 | PeerConnectionIceTestPlanB() |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1208 | : PeerConnectionIceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {} |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1209 | }; |
| 1210 | |
| 1211 | TEST_F(PeerConnectionIceTestPlanB, |
| 1212 | RestartIceWhileOfferIsPendingCausesNegotiationNeededImmediately) { |
| 1213 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1214 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1215 | |
| 1216 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1217 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1218 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1219 | caller->pc()->RestartIce(); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1220 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1221 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
| 1222 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1223 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1224 | ASSERT_TRUE( |
| 1225 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1226 | // In Plan B, the event fired early so we don't expect it to fire now. This is |
| 1227 | // not spec-compliant but follows the pattern of existing Plan B behavior. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1228 | EXPECT_FALSE(caller->observer()->legacy_renegotiation_needed()); |
| 1229 | EXPECT_FALSE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | TEST_F(PeerConnectionIceTestPlanB, |
| 1233 | RestartIceTwiceDoesFireNegotiationNeededTwice) { |
| 1234 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1235 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1236 | |
| 1237 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1238 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1239 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1240 | caller->pc()->RestartIce(); |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1241 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1242 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
| 1243 | caller->observer()->clear_legacy_renegotiation_needed(); |
| 1244 | caller->observer()->clear_latest_negotiation_needed_event(); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1245 | caller->pc()->RestartIce(); |
| 1246 | // In Plan B, the event fires every time something changed, even if we have |
| 1247 | // already fired the event. This is not spec-compliant but follows the same |
| 1248 | // pattern of existing Plan B behavior. |
Henrik Boström | e574a31 | 2020-08-25 10:20:11 +0200 | [diff] [blame] | 1249 | EXPECT_TRUE(caller->observer()->legacy_renegotiation_needed()); |
| 1250 | EXPECT_TRUE(caller->observer()->has_negotiation_needed_event()); |
Henrik Boström | 79b6980 | 2019-07-18 11:16:56 +0200 | [diff] [blame] | 1251 | } |
| 1252 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1253 | // The following parameterized test verifies that if an offer is sent with a |
| 1254 | // modified ICE ufrag and/or ICE pwd, then the answer should identify that the |
| 1255 | // other side has initiated an ICE restart and generate a new ufrag and pwd. |
| 1256 | // RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or |
| 1257 | // a=ice-pwd attributes compared to the previous SDP from the peer, it |
| 1258 | // indicates that ICE is restarting for this media stream." |
| 1259 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1260 | class PeerConnectionIceUfragPwdAnswerTest |
| 1261 | : public PeerConnectionIceBaseTest, |
| 1262 | public ::testing::WithParamInterface< |
| 1263 | std::tuple<SdpSemantics, std::tuple<bool, bool>>> { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1264 | protected: |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1265 | PeerConnectionIceUfragPwdAnswerTest() |
| 1266 | : PeerConnectionIceBaseTest(std::get<0>(GetParam())) { |
| 1267 | auto param = std::get<1>(GetParam()); |
| 1268 | offer_new_ufrag_ = std::get<0>(param); |
| 1269 | offer_new_pwd_ = std::get<1>(param); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | bool offer_new_ufrag_; |
| 1273 | bool offer_new_pwd_; |
| 1274 | }; |
| 1275 | |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1276 | TEST_P(PeerConnectionIceUfragPwdAnswerTest, TestIncludedInAnswer) { |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1277 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1278 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1279 | |
| 1280 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1281 | ASSERT_TRUE( |
| 1282 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1283 | |
| 1284 | auto offer = caller->CreateOffer(); |
| 1285 | auto* offer_transport_desc = GetFirstTransportDescription(offer.get()); |
| 1286 | if (offer_new_ufrag_) { |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 1287 | offer_transport_desc->ice_ufrag += "+new"; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1288 | } |
| 1289 | if (offer_new_pwd_) { |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 1290 | offer_transport_desc->ice_pwd += "+new"; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1294 | |
| 1295 | auto answer = callee->CreateAnswer(); |
| 1296 | auto* answer_transport_desc = GetFirstTransportDescription(answer.get()); |
| 1297 | auto* local_transport_desc = |
| 1298 | GetFirstTransportDescription(callee->pc()->local_description()); |
| 1299 | |
| 1300 | EXPECT_NE(answer_transport_desc->ice_ufrag, local_transport_desc->ice_ufrag); |
| 1301 | EXPECT_NE(answer_transport_desc->ice_pwd, local_transport_desc->ice_pwd); |
| 1302 | } |
| 1303 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 1304 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1305 | PeerConnectionIceTest, |
| 1306 | PeerConnectionIceUfragPwdAnswerTest, |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1307 | Combine(Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan), |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1308 | Values(std::make_pair(true, true), // Both changed. |
| 1309 | std::make_pair(true, false), // Only ufrag changed. |
| 1310 | std::make_pair(false, true)))); // Only pwd changed. |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1311 | |
| 1312 | // Test that if an ICE restart is offered on one media section, then the answer |
| 1313 | // will only change ICE ufrag/pwd for that section and keep the other sections |
| 1314 | // the same. |
| 1315 | // Note that this only works if we have disabled BUNDLE, otherwise all media |
| 1316 | // sections will share the same transport. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1317 | TEST_P(PeerConnectionIceTest, |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1318 | CreateAnswerHasNewUfragPwdForOnlyMediaSectionWhichRestarted) { |
| 1319 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1320 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1321 | |
| 1322 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1323 | ASSERT_TRUE( |
| 1324 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1325 | |
| 1326 | RTCOfferAnswerOptions disable_bundle_options; |
| 1327 | disable_bundle_options.use_rtp_mux = false; |
| 1328 | |
| 1329 | auto offer = caller->CreateOffer(disable_bundle_options); |
| 1330 | |
| 1331 | // Signal ICE restart on the first media section. |
| 1332 | auto* offer_transport_desc = GetFirstTransportDescription(offer.get()); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 1333 | offer_transport_desc->ice_ufrag += "+new"; |
| 1334 | offer_transport_desc->ice_pwd += "+new"; |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1335 | |
| 1336 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1337 | |
| 1338 | auto answer = callee->CreateAnswer(disable_bundle_options); |
| 1339 | const auto& answer_transports = answer->description()->transport_infos(); |
| 1340 | const auto& local_transports = |
| 1341 | callee->pc()->local_description()->description()->transport_infos(); |
| 1342 | |
| 1343 | EXPECT_NE(answer_transports[0].description.ice_ufrag, |
| 1344 | local_transports[0].description.ice_ufrag); |
| 1345 | EXPECT_NE(answer_transports[0].description.ice_pwd, |
| 1346 | local_transports[0].description.ice_pwd); |
| 1347 | EXPECT_EQ(answer_transports[1].description.ice_ufrag, |
| 1348 | local_transports[1].description.ice_ufrag); |
| 1349 | EXPECT_EQ(answer_transports[1].description.ice_pwd, |
| 1350 | local_transports[1].description.ice_pwd); |
| 1351 | } |
| 1352 | |
Qingsi Wang | e169272 | 2017-11-29 13:27:20 -0800 | [diff] [blame] | 1353 | // Test that when the initial offerer (caller) uses the lite implementation of |
| 1354 | // ICE and the callee uses the full implementation, the caller takes the |
| 1355 | // CONTROLLED role and the callee takes the CONTROLLING role. This is specified |
| 1356 | // in RFC5245 Section 5.1.1. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1357 | TEST_P(PeerConnectionIceTest, |
Qingsi Wang | e169272 | 2017-11-29 13:27:20 -0800 | [diff] [blame] | 1358 | OfferFromLiteIceControlledAndAnswerFromFullIceControlling) { |
| 1359 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1360 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1361 | |
| 1362 | auto offer = caller->CreateOffer(); |
| 1363 | SetIceMode(offer.get(), cricket::IceMode::ICEMODE_LITE); |
| 1364 | ASSERT_TRUE( |
| 1365 | caller->SetLocalDescription(CloneSessionDescription(offer.get()))); |
| 1366 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1367 | |
| 1368 | auto answer = callee->CreateAnswer(); |
| 1369 | SetIceMode(answer.get(), cricket::IceMode::ICEMODE_FULL); |
| 1370 | ASSERT_TRUE( |
| 1371 | callee->SetLocalDescription(CloneSessionDescription(answer.get()))); |
| 1372 | ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer))); |
| 1373 | |
| 1374 | EXPECT_EQ(cricket::ICEROLE_CONTROLLED, GetIceRole(caller)); |
| 1375 | EXPECT_EQ(cricket::ICEROLE_CONTROLLING, GetIceRole(callee)); |
| 1376 | } |
| 1377 | |
| 1378 | // Test that when the caller and the callee both use the lite implementation of |
| 1379 | // ICE, the initial offerer (caller) takes the CONTROLLING role and the callee |
| 1380 | // takes the CONTROLLED role. This is specified in RFC5245 Section 5.1.1. |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1381 | TEST_P(PeerConnectionIceTest, |
Qingsi Wang | e169272 | 2017-11-29 13:27:20 -0800 | [diff] [blame] | 1382 | OfferFromLiteIceControllingAndAnswerFromLiteIceControlled) { |
| 1383 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1384 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1385 | |
| 1386 | auto offer = caller->CreateOffer(); |
| 1387 | SetIceMode(offer.get(), cricket::IceMode::ICEMODE_LITE); |
| 1388 | ASSERT_TRUE( |
| 1389 | caller->SetLocalDescription(CloneSessionDescription(offer.get()))); |
| 1390 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1391 | |
| 1392 | auto answer = callee->CreateAnswer(); |
| 1393 | SetIceMode(answer.get(), cricket::IceMode::ICEMODE_LITE); |
| 1394 | ASSERT_TRUE( |
| 1395 | callee->SetLocalDescription(CloneSessionDescription(answer.get()))); |
| 1396 | ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer))); |
| 1397 | |
| 1398 | EXPECT_EQ(cricket::ICEROLE_CONTROLLING, GetIceRole(caller)); |
| 1399 | EXPECT_EQ(cricket::ICEROLE_CONTROLLED, GetIceRole(callee)); |
| 1400 | } |
| 1401 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 1402 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIceTest, |
| 1403 | PeerConnectionIceTest, |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1404 | Values(SdpSemantics::kPlanB_DEPRECATED, |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 1405 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | 46d926a | 2018-01-23 10:23:06 -0800 | [diff] [blame] | 1406 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 1407 | class PeerConnectionIceConfigTest : public ::testing::Test { |
Byoungchan Lee | d58f526 | 2022-06-27 18:05:22 +0900 | [diff] [blame] | 1408 | public: |
| 1409 | PeerConnectionIceConfigTest() |
| 1410 | : socket_server_(rtc::CreateDefaultSocketServer()), |
| 1411 | main_thread_(socket_server_.get()) {} |
| 1412 | |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1413 | protected: |
| 1414 | void SetUp() override { |
| 1415 | pc_factory_ = CreatePeerConnectionFactory( |
| 1416 | rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
| 1417 | FakeAudioCaptureModule::Create(), CreateBuiltinAudioEncoderFactory(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 1418 | CreateBuiltinAudioDecoderFactory(), CreateBuiltinVideoEncoderFactory(), |
| 1419 | CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 1420 | nullptr /* audio_processing */); |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1421 | } |
| 1422 | void CreatePeerConnection(const RTCConfiguration& config) { |
Byoungchan Lee | d58f526 | 2022-06-27 18:05:22 +0900 | [diff] [blame] | 1423 | packet_socket_factory_.reset( |
| 1424 | new rtc::BasicPacketSocketFactory(socket_server_.get())); |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1425 | std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
Byoungchan Lee | d58f526 | 2022-06-27 18:05:22 +0900 | [diff] [blame] | 1426 | new cricket::FakePortAllocator(rtc::Thread::Current(), |
| 1427 | packet_socket_factory_.get())); |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1428 | port_allocator_ = port_allocator.get(); |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1429 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 1430 | pc_dependencies.allocator = std::move(port_allocator); |
| 1431 | auto result = pc_factory_->CreatePeerConnectionOrError( |
| 1432 | config, std::move(pc_dependencies)); |
| 1433 | EXPECT_TRUE(result.ok()); |
| 1434 | pc_ = result.MoveValue(); |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1435 | } |
| 1436 | |
Byoungchan Lee | d58f526 | 2022-06-27 18:05:22 +0900 | [diff] [blame] | 1437 | std::unique_ptr<rtc::SocketServer> socket_server_; |
| 1438 | rtc::AutoSocketServerThread main_thread_; |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1439 | rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_ = nullptr; |
| 1440 | rtc::scoped_refptr<PeerConnectionInterface> pc_ = nullptr; |
Byoungchan Lee | d58f526 | 2022-06-27 18:05:22 +0900 | [diff] [blame] | 1441 | std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_; |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1442 | cricket::FakePortAllocator* port_allocator_ = nullptr; |
| 1443 | |
| 1444 | MockPeerConnectionObserver observer_; |
| 1445 | }; |
| 1446 | |
| 1447 | TEST_F(PeerConnectionIceConfigTest, SetStunCandidateKeepaliveInterval) { |
| 1448 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1449 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1450 | config.stun_candidate_keepalive_interval = 123; |
| 1451 | config.ice_candidate_pool_size = 1; |
| 1452 | CreatePeerConnection(config); |
| 1453 | ASSERT_NE(port_allocator_, nullptr); |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 1454 | absl::optional<int> actual_stun_keepalive_interval = |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1455 | port_allocator_->stun_candidate_keepalive_interval(); |
| 1456 | EXPECT_EQ(actual_stun_keepalive_interval.value_or(-1), 123); |
| 1457 | config.stun_candidate_keepalive_interval = 321; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 1458 | ASSERT_TRUE(pc_->SetConfiguration(config).ok()); |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 1459 | actual_stun_keepalive_interval = |
| 1460 | port_allocator_->stun_candidate_keepalive_interval(); |
| 1461 | EXPECT_EQ(actual_stun_keepalive_interval.value_or(-1), 321); |
| 1462 | } |
| 1463 | |
Derek Bailey | 6c127a1 | 2021-04-15 12:42:41 -0700 | [diff] [blame] | 1464 | TEST_F(PeerConnectionIceConfigTest, SetStableWritableConnectionInterval) { |
| 1465 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1466 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Derek Bailey | 6c127a1 | 2021-04-15 12:42:41 -0700 | [diff] [blame] | 1467 | config.stable_writable_connection_ping_interval_ms = 3500; |
| 1468 | CreatePeerConnection(config); |
| 1469 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
| 1470 | EXPECT_EQ(pc_->GetConfiguration().stable_writable_connection_ping_interval_ms, |
| 1471 | config.stable_writable_connection_ping_interval_ms); |
| 1472 | } |
| 1473 | |
| 1474 | TEST_F(PeerConnectionIceConfigTest, |
| 1475 | SetStableWritableConnectionInterval_FailsValidation) { |
| 1476 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1477 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Derek Bailey | 6c127a1 | 2021-04-15 12:42:41 -0700 | [diff] [blame] | 1478 | CreatePeerConnection(config); |
| 1479 | ASSERT_TRUE(pc_->SetConfiguration(config).ok()); |
| 1480 | config.stable_writable_connection_ping_interval_ms = 5000; |
| 1481 | config.ice_check_interval_strong_connectivity = 7500; |
| 1482 | EXPECT_FALSE(pc_->SetConfiguration(config).ok()); |
| 1483 | } |
| 1484 | |
| 1485 | TEST_F(PeerConnectionIceConfigTest, |
| 1486 | SetStableWritableConnectionInterval_DefaultValue_FailsValidation) { |
| 1487 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1488 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Derek Bailey | 6c127a1 | 2021-04-15 12:42:41 -0700 | [diff] [blame] | 1489 | CreatePeerConnection(config); |
| 1490 | ASSERT_TRUE(pc_->SetConfiguration(config).ok()); |
| 1491 | config.ice_check_interval_strong_connectivity = 2500; |
| 1492 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
| 1493 | config.ice_check_interval_strong_connectivity = 2501; |
| 1494 | EXPECT_FALSE(pc_->SetConfiguration(config).ok()); |
| 1495 | } |
| 1496 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1497 | TEST_P(PeerConnectionIceTest, IceCredentialsCreateOffer) { |
| 1498 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1499 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1500 | config.ice_candidate_pool_size = 1; |
| 1501 | auto pc = CreatePeerConnectionWithAudioVideo(config); |
| 1502 | ASSERT_NE(pc->port_allocator_, nullptr); |
| 1503 | auto offer = pc->CreateOffer(); |
| 1504 | auto credentials = pc->port_allocator_->GetPooledIceCredentials(); |
| 1505 | ASSERT_EQ(1u, credentials.size()); |
| 1506 | |
| 1507 | auto* desc = offer->description(); |
| 1508 | for (const auto& content : desc->contents()) { |
| 1509 | auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 1510 | EXPECT_EQ(transport_info->description.ice_ufrag, credentials[0].ufrag); |
| 1511 | EXPECT_EQ(transport_info->description.ice_pwd, credentials[0].pwd); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | TEST_P(PeerConnectionIceTest, IceCredentialsCreateAnswer) { |
| 1516 | RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1517 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1518 | config.ice_candidate_pool_size = 1; |
| 1519 | auto pc = CreatePeerConnectionWithAudioVideo(config); |
| 1520 | ASSERT_NE(pc->port_allocator_, nullptr); |
| 1521 | auto offer = pc->CreateOffer(); |
| 1522 | ASSERT_TRUE(pc->SetRemoteDescription(std::move(offer))); |
| 1523 | auto answer = pc->CreateAnswer(); |
| 1524 | |
| 1525 | auto credentials = pc->port_allocator_->GetPooledIceCredentials(); |
| 1526 | ASSERT_EQ(1u, credentials.size()); |
| 1527 | |
| 1528 | auto* desc = answer->description(); |
| 1529 | for (const auto& content : desc->contents()) { |
| 1530 | auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 1531 | EXPECT_EQ(transport_info->description.ice_ufrag, credentials[0].ufrag); |
| 1532 | EXPECT_EQ(transport_info->description.ice_pwd, credentials[0].pwd); |
| 1533 | } |
| 1534 | } |
| 1535 | |
Steve Anton | ec47b57 | 2020-01-24 14:53:37 -0800 | [diff] [blame] | 1536 | // Regression test for https://bugs.chromium.org/p/webrtc/issues/detail?id=4728 |
| 1537 | TEST_P(PeerConnectionIceTest, CloseDoesNotTransitionGatheringStateToComplete) { |
| 1538 | auto pc = CreatePeerConnectionWithAudioVideo(); |
| 1539 | pc->pc()->Close(); |
| 1540 | EXPECT_FALSE(pc->IsIceGatheringDone()); |
| 1541 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 1542 | pc->pc()->ice_gathering_state()); |
| 1543 | } |
| 1544 | |
Philipp Hancke | 31e06cb | 2021-02-26 09:23:53 +0100 | [diff] [blame] | 1545 | TEST_P(PeerConnectionIceTest, PrefersMidOverMLineIndex) { |
| 1546 | const SocketAddress kCalleeAddress("1.1.1.1", 1111); |
| 1547 | |
| 1548 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1549 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1550 | |
| 1551 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1552 | ASSERT_TRUE( |
| 1553 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1554 | |
Artem Titov | cfea218 | 2021-08-10 01:22:31 +0200 | [diff] [blame] | 1555 | // `candidate.transport_name()` is empty. |
Philipp Hancke | 31e06cb | 2021-02-26 09:23:53 +0100 | [diff] [blame] | 1556 | cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); |
| 1557 | auto* audio_content = cricket::GetFirstAudioContent( |
| 1558 | caller->pc()->local_description()->description()); |
| 1559 | std::unique_ptr<IceCandidateInterface> ice_candidate = |
| 1560 | CreateIceCandidate(audio_content->name, 65535, candidate); |
| 1561 | EXPECT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get())); |
| 1562 | EXPECT_TRUE(caller->pc()->RemoveIceCandidates({candidate})); |
| 1563 | } |
| 1564 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1565 | } // namespace webrtc |